In the first case you first throw from the try
block and then the stack unwinding throws from Cls
's destructor. So you have two exceptions to be handled. C++ handles this situation by calling terminate
.
Because of the peculiarity of throwing from destructors, C++11 defines that all destructors are noexcept
by default. Then even if there is no other exception to be handled, the exception from a destructor will cause terminate
to be called.
The second case is OK because as soon as you throw the first exception try
block is left and the exception is handled in the catch
block.