Exceptions thrown during the initialization of global objects result in a call to terminate and thus cause the program to abort without diagnostics. If desired, you can use set_terminate to specify some other exception-handling routine to be used in the event of an unforeseen program abort. This function must, however, be called before initializing the global objects.
The C++ runtime system offers the following solution to specify functions to be used as the “initial current handler”:
You can link your own
__initial_terminate_handlerfunction of typeterminate_handlerinto your program. This function is declaredweakin the C++ runtime system. If__initial_terminate_handleris defined, the function will then be called as the “initial handler” to terminate exception processing.You can also use the functions
__initial_unexpected_handlerand__initial_new_handlerwith the same mechanism. These routines are of typeunexpected_handlerandnew_handler, respectively.
You must include the header file <exception> for the __initial_terminate_handler and __initial_unexpected_handler interfaces and the header file <new> for the __initial_new_handler.