set_terminate (<exception>)

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

terminate_handler
   set_terminate(
      terminate_handler _Pnew
   ) throw( );

Parameters

  • _Pnew
    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 *_Pnew. Thus, _Pnew must not be a null pointer. The function returns the address of the previous terminate handler.

Example

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

using namespace std;

void termfunction( ) 
{
   cout << "I'll be back." << endl;
   abort( );
}

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

   // Throwing an unhandled exception would also terminate the program
   throw bad_alloc( );

   // The program could also be explicitely terminated with:
   // terminate( );
}

I'll be back.

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Requirements

Header: <exception>

Namespace: std

See Also

Other Resources

<exception> Members