| View previous topic :: View next topic |
| Author |
Message |
Gianluca Silvestri Guest
|
Posted: Thu Feb 23, 2006 1:06 am Post subject: Is throwing an exception in a handler legal? |
|
|
Hi all,
Until now I was pretty sure that throwing an exception from inside a
catch() handler other than re-throwing the current handled exception
was a no-no.
But now I cannot find any reference in the Standard or even on TCPPL
supporting thi claim.
Is it true? If so, what are the references?
Thanks
Gianluca Silvestri
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Bob Bell Guest
|
Posted: Thu Feb 23, 2006 11:06 am Post subject: Re: Is throwing an exception in a handler legal? |
|
|
Gianluca Silvestri wrote:
| Quote: | Hi all,
Until now I was pretty sure that throwing an exception from inside a
catch() handler other than re-throwing the current handled exception
was a no-no.
But now I cannot find any reference in the Standard or even on TCPPL
supporting thi claim.
Is it true? If so, what are the references?
|
It's not true. You can throw anything you want from inside a catch
handler.
Bob
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Bronek Kozicki Guest
|
Posted: Thu Feb 23, 2006 1:06 pm Post subject: Re: Is throwing an exception in a handler legal? |
|
|
Gianluca Silvestri <dishsi (AT) tin (DOT) it> wrote:
| Quote: | Until now I was pretty sure that throwing an exception from inside a
catch() handler other than re-throwing the current handled exception
was a no-no.
|
mistake. Throwing an exception inside catch is rather normal practice if
exception must be partly handled locally and then passed to caller:
try
{
//...
}
catch(...)
{
log_error();
throw;
}
..... in translation of exceptions:
try
{
//...
}
catch(std::exception& e)
{
throw ApplicationSpecificError(typeid(e), e.what());
}
.... and in exception filtering:
int filter()
{
try
{
throw;
}
catch (std::bad_alloc& e)
{
return E_MEMORY_DEPLETED;
}
catch (std::overflow_error& e)
{
return E_OVERFLOW;
}
catch (ApplicationSpecificError& e)
{
return e.code();
}
catch (std::exception& e)
{
return E_GENERAL_FAILURE;
}
}
// binary module boundary, must not throw C++ exceptions
int foo() throw ()
{
try
{
//...
}
catch(...)
{
return filter();
}
return SUCCESS;
}
B.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Thu Feb 23, 2006 3:06 pm Post subject: Re: Is throwing an exception in a handler legal? |
|
|
In article <1140617420.274026.83680 (AT) o13g2000cwo (DOT) googlegroups.com>,
Gianluca Silvestri <dishsi (AT) tin (DOT) it> writes
| Quote: | Hi all,
Until now I was pretty sure that throwing an exception from inside a
catch() handler other than re-throwing the current handled exception
was a no-no.
But now I cannot find any reference in the Standard or even on TCPPL
supporting thi claim.
Is it true? If so, what are the references?
|
Difficult to provide references when it isn't (true that is):-)
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Jeffrey Schwab Guest
|
Posted: Thu Feb 23, 2006 3:06 pm Post subject: Re: Is throwing an exception in a handler legal? |
|
|
Gianluca Silvestri wrote:
| Quote: | Hi all,
Until now I was pretty sure that throwing an exception from inside a
catch() handler other than re-throwing the current handled exception
was a no-no.
But now I cannot find any reference in the Standard or even on TCPPL
supporting thi claim.
Is it true? If so, what are the references?
|
Might you be thinking of the guideline that exceptions should not be
thrown from destructors?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Gianluca Silvestri Guest
|
Posted: Thu Feb 23, 2006 7:06 pm Post subject: Re: Is throwing an exception in a handler legal? |
|
|
Gianluca Silvestri wrote:
| Quote: | Hi all,
Until now I was pretty sure that throwing an exception from inside a
catch() handler other than re-throwing the current handled exception
was a no-no.
But now I cannot find any reference in the Standard or even on TCPPL
supporting thi claim.
Is it true? If so, what are the references?
|
Thanks to all. I don't remember when or where I read about this.
Probably I was confused by the rules about throwing an exception in a
destructor during stack unwinding.
Gianluca Silvestri
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|