set_terminate() — Register a function for terminate()

Standards

Standards / Extensions C or C++ Dependencies

ANSI/ISO
C++

C++ only  

Format

#include <exception>

terminate_handler set_terminate(terminate_handler ph) throw();

General description

The set_terminate() function is part of the z/OS® XL C++ error handling mechanism. The argument supplied to set_terminate() is of type terminate_handler as defined in the header <exception> (that is, a pointer to a function with a void return type and no arguments). The function specified will be called by the terminate() function.

Note that the function registered for terminate() must terminate execution of the program without returning to its caller(). If set_terminate() has not yet been called, then terminate() calls a system-defined default terminate handler, which calls abort().

In a multithreaded environment, the terminate function created by the issuance of a set_terminate() call applies to all threads in the (POSIX) process. If a thread throws an exception which is not caught by that thread of execution, then terminate() is called. The default terminate() action calls abort() which by default cause a SIGABRT signal. If there is no signal handler, then SIGABRT terminates the process. You can override this with a thread-level termination by supplying a function which invokes pthread_exit() as a terminate function. This terminates the thread but not the process.

Returned value

set_terminate() returns the address of the previous terminate_handler.

Refer to z/OS XL C/C++ Language Reference for more information about z/OS XL C++ exception handling, including the set_terminate() function.

Related information