Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C++
Reference
Libraries Reference
<exception>
Functions
 set_terminate
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Standard C++ Library Reference 
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.

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

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.

Header: <exception>

Other Resources

<exception> Members

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker