다음을 통해 공유


set_terminate (<exception>)

Establishes a new terminate_handler to be called at the termination of the program.

terminate_handler 
   set_terminate( 
      terminate_handler fnew 
   ) throw( );

Parameters

  • fnew
    The function to be called at termination.

Return Value

The address of the previous function that used to be called at termination.

Remarks

The function establishes a new terminate_handler as the function *fnew. Thus, fnew must not be a null pointer. The function returns the address of the previous terminate handler.

Example

// exception_set_terminate.cpp
// compile with: /EHsc
#include <exception>
#include <iostream>

using namespace std;

void termfunction()
{
    cout << "My terminate function called." << endl;
    abort();
}

int main()
{
    terminate_handler oldHandler = set_terminate(termfunction);

    // Throwing an unhandled exception would also terminate the program
    // or we could explicitly call terminate();
    
    //throw bad_alloc();
    terminate();
}

Output

My terminate function called.

Requirements

Header: <exception>

Namespace: std

See Also

Reference

<exception>

get_terminate