C++ Programming Guide

set_terminate()

You can modify the default behavior of terminate() by calling the function set_terminate(), as shown in the following example.


// declarations are in standard header <exception>
namespace std {
   typedef void (*terminate_handler)();
   terminate_handler set_terminate(terminate_handler f) throw();
   void terminate();
}

The terminate() function is called in any of the following circumstances:

The terminate() function calls the function passed as an argument to set_terminate(). Such a function takes no parameters, returns no value, and must terminate the program (or the current thread). The function passed in the most recent call to set_terminate() is called. The previous function passed as an argument to set_terminate() is the return value, so you can implement a stack strategy for using terminate(). The default function for terminate() calls abort() for the main thread and thr_exit() for other threads. Note that thr_exit() does not unwind the stack or call C++ destructors for automatic objects.


Note -

Selecting a terminate() replacement that returns to its caller, or that does not terminate the program or thread, is an error.