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

Return Value

The address of the previous unexpected_handler.

Remarks

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

Example

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

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