This documentation is archived and is not being maintained.

set_unexpected (<exception>) 

Establishes a new unexpected_handler to be when an unexpected exception is encountered.


unexpected_handler
   set_unexpected(
      unexpected_handler _Pnew
   ) throw( );

Parameters

_Pnew

The function to be called at

The address of the previous unexpected_handler.

_Pnew must not be a null pointer.

The C++ Standard requires that unexpected is called when a function throws an exception that is not on its throw list. The current implementation does not support this. The following example calls unexpected directly, which then calls the unexpected_handler.

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

using namespace std;

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

int main( ) 
{
   unexpected_handler oldHand = set_unexpected( unfunction );
   unexpected( );
}

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>

Show: