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_handler
function of typeterminate_handler
into your program. This function is declaredweak
in the C++ runtime system. If__initial_terminate_handler
is defined, the function will then be called as the “initial handler” to terminate exception processing.You can also use the functions
__initial_unexpected_handler
and__initial_new_handler
with the same mechanism. These routines are of typeunexpected_handler
andnew_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
.