Export (0) Print
Expand All

set_terminate

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

terminate_handler
   set_terminate(
      terminate_handler _Pnew
   ) throw( );

Parameter

_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
#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( );
}

Output

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.

See Also

<exception> Members

Show:
© 2014 Microsoft