Suppose a program with some global resources in it, and in the middle of the code, an exception is thrown which is not caught and the program ends with a call to std::terminate
.
If I install an std::terminate_handler
, which is called by std::terminate
, and my handler calls std::current_exception
, I want to know if I’m guaranteed to have these global resources available at that time:
- Will
std::terminate
be called before or after all the destructors of all global resources are destroyed? Or the call happens just after it’s detected the stack frame ofmain
is abandoned, but before all the global state is destroyed? - In which thread will
std::terminate
be called, in the main thread always, or in the thread that didn’t catch the exception?
The point is to know what is guaranteed to exist before the call to the handler.
6