 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
josh Guest
|
Posted: Wed May 16, 2007 9:10 am Post subject: chained exception |
|
|
Hi,
is there a standard way to "read" an exception rethrowed by a catch
and catch in an another extern try/catch?
Thanks |
|
| Back to top |
|
 |
comp.lang.c++ Guest
|
Posted: Wed May 16, 2007 9:10 am Post subject: Re: chained exception |
|
|
i thank,so
"josh" <xdevel1999 (AT) gmail (DOT) com>
??????:1179302043.101088.112800 (AT) y80g2000hsf (DOT) googlegroups.com...
| Quote: | Hi,
is there a standard way to "read" an exception rethrowed by a catch
and catch in an another extern try/catch?
Thanks
|
|
|
| Back to top |
|
 |
peter koch Guest
|
Posted: Wed May 16, 2007 9:11 am Post subject: Re: chained exception |
|
|
On 16 Maj, 09:54, josh <xdevel1...@gmail.com> wrote:
| Quote: | Hi,
is there a standard way to "read" an exception rethrowed by a catch
and catch in an another extern try/catch?
Thanks
|
The idiom is something like this:
void detect_exception()
{
try
{
throw;
}
catch (std::exception const& se)
{
// std::exception thrown
}
catch (myexception const& me)
{
// myexception thrown
}
catch (...)
{
// something else thrown
}
}
/Peter |
|
| Back to top |
|
 |
Sylvester Hesp Guest
|
Posted: Wed May 16, 2007 9:11 am Post subject: Re: chained exception |
|
|
"josh" <xdevel1999 (AT) gmail (DOT) com> wrote in message
news:1179302043.101088.112800 (AT) y80g2000hsf (DOT) googlegroups.com...
| Quote: | Hi,
is there a standard way to "read" an exception rethrowed by a catch
and catch in an another extern try/catch?
Thanks
|
Sure there is, just use nested try/catch statements
#include <iostream>
int main()
{
try
{
try
{
std::cout << "throwing..." << std::endl;
throw 42;
}
catch(int i)
{
std::cout << "Inner catch: " << i << " - rethrowing..." <<
std::endl;
throw;
}
}
catch(int i)
{
std::cout << "Outer catch: " << i << std::endl;
}
}
Of course, the inner and outer catches don't have to be in the same
function, and the outer catch can rethrow again if deemed necessary.
- Sylvester |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|