Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

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

// 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.

Header: <exception>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.