Skip to content
Search

Std::set terminate

lastmod 2018-08-17created 2016-12-253 edits

Installs your own termination routine to be called by terminate.

Syntax

terminate_function set_terminate(  
   terminate_function termFunction  
);  

Return

Returns a pointer to the previous function registered by set_terminate, so that the previous function can be restored later. If no previous function has been set, the return value may be used to restore the default behavior; this value may be NULL.

Remarks

The set_terminate function installs termFunction as the function called by terminate. set_terminate is used with C++ exception handling and may be called at any pointer in your program before the exception is thrown. terminate calls abort by default. You can change this default by writing your own termination function and calling set_terminate with the name of your function as its argument. terminate always calls the last function given as an argument to set_terminate. After performing any desired cleanup tasks, termFunction should exit the program. If it does not exit (if it returns to its caller), abort is called.

WARNING

In a multithreaded environment, terminate functions are maintained separately for each thread. Each new thread needs to install its own terminate function. Thus, each thread is in charge of its own termination handling.

The terminate_function type is defined in EH.H as a pointer to a user-defined termination function, termFunction, that returns void. Your custom function termFunction can take arguments and should not return to its caller. If it does, abort is called. An exception may not be thrown from within termFunction.

WARNING

Whether the stack of the function that threw an unhandled exception is unwound depends on the compiler.

Example

#include <Turboc.h>
#include <exception>

using namespace std;

void myterm()
{
    puts("처리되지 않은 예외 발생");
    exit(-1);
}

void main()
{
    set_terminate(myterm);
    try {
        throw 1;
    } catch (char * m) {
        // EMPTY.
    }
}

See also

Favorite site