set_terminate (<exception>)

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

      terminate_handler fnew 
   ) throw( );


The function to be called at termination.

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

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.

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

using namespace std;

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

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();

My terminate function called.

Header: <exception>

Namespace: std

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft