Captures (...) the work on the cast; without an object?

What does the C ++ standard say for the following code when the exception handled is not handled above the stack?

try { throw; } catch (...) { cerr << "Caught exception." << endl; } 

Will a throw be detected without an object?

+4
source share
1 answer

From the C ++ 2003 Standard ยง15.1 [except.throw] / 8:

If no exception is currently thrown, the throw statement is executed without any terminate() operands.

So, in your example, since no exception is currently being handled, nothing is thrown, and terminate() is called instead. Since terminate() not returned, your catch will never be entered.

+12
source

All Articles