Consider this:
void thrower () { throw "123"; } struct Catcher { ~ Catcher () { try {thrower ();} catch (...) {} } }; int main () { try { Catcher c; throw 1.23; } catch (...) {} }
This compiles and runs without calling terminate
in gcc 4.3, but according to the standard (15.5.1)
... when the exception handling mechanism, after completing the evaluation of the expressed expression, but before the exception is caught (15.1), calls the user function, which exits through the uncaught exception ... completion must be called.
When the ~Catcher
call is called after the double has been reset, it is "after the evaluation is complete ... before the exception is caught", and thrower
is the "user-defined function that leaves the uncaught exception", this satisfies the above condition. Yes, char*
caught, but only after the user function exits.
Should I call terminate
?
To emphasize this:
void do_throw () { throw "123"; } void thrower () { do_throw ();
(A) occurs in context (B), which already has an exception.
So should terminate
not be called? If not, and this is a legal situation in which we can have two simultaneous exceptions, where do we draw the line?
source share