terminate() — Terminate after failures in C++ error handling

Standards

Standards / Extensions C or C++ Dependencies

ANSI/ISO
C++

C++ only  

Format

#include <exception>

void terminate(void);

General description

The terminate() function is called when the C++ error handling mechanism fails. If terminate() is called directly by the program, the terminate_handler is the one most recently set by a call to set_terminate(). If terminate() is called for any of several other reasons during evaluation of a throw expression, the terminate_handler is the one in effect immediately after evaluating the throw expression. If set_terminate() has not yet been called, then terminate() calls abort().

In a multithreaded environment, if a thread issues a throw, the stack is unwound until a matching catcher is found, up to and including the thread start routine. (The thread start routine is the function passed to pthread_create().) If the exception is not caught, then the terminate() function is called, which in turn defaults to calling abort(), which in turn causes a SIGABRT signal to be generated to the thread issuing the throw. If the SIGABRT signal is not caught, the process is terminated. You can replace the default terminate() behavior for all threads in the process by using the set_terminate() function. One possible use of set_terminate() is to call a function which issues a pthread_exit(). If this is done, a throw of a condition by a thread that is uncaught results in thread termination but not process termination.

Returned value

terminate() returns no values.

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

Related information