I'm currently following C++ core guidelines setting all destructors in my code to be noexcept
. Some of my destructors may potentially throw exceptions - in that case I would like the program to crash and provide me with details on what caused the crash. Setting the noexcept
specifier on the destructor will call std::terminate()
which in turns invoke the default terminate_handler
. The default terminate_handler
will print the exception which was fired inside the destructor. This is great in the case in which the throwing destructor was not called while another exception was being thrown. In that case I would like the terminate_handler
to print both exceptions so I can know what triggered the error handling path in the first place.
The problem is I can't seem to find a way in the standard library to get the uncaught exception. There's a std::current_exception()
function which gets the exception being handled and std::uncaught_exceptions()
which only gets the number of uncaught exception. I would like to get an std::exception_ptr
or something to the uncaught exceptions. Is that possible?