C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

chained exception

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
josh
Guest





PostPosted: Wed May 16, 2007 9:10 am    Post subject: chained exception Reply with 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
comp.lang.c++
Guest





PostPosted: Wed May 16, 2007 9:10 am    Post subject: Re: chained exception Reply with quote



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





PostPosted: Wed May 16, 2007 9:11 am    Post subject: Re: chained exception Reply with quote



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





PostPosted: Wed May 16, 2007 9:11 am    Post subject: Re: chained exception Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.