set_unexpected (<exception>)

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

unexpected_handler 
   set_unexpected( 
      unexpected_handler fnew 
   ) throw( );

Parameters

  • fnew
    The function to be called when an unexpected exception is encountered.

Return Value

The address of the previous unexpected_handler.

Remarks

fnew 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: /EHsc
#include <exception>
#include <iostream>

using namespace std;

void uefunction()
{
    cout << "My unhandled exception function called." << endl;
    terminate(); // this is what unexpected() calls by default
}

int main()
{
    unexpected_handler oldHandler = set_unexpected(uefunction);

    unexpected(); // library function to force calling the 
                  // current unexpected handler
}

Output

My unhandled exception function called.

Requirements

Header: <exception>

Namespace: std

See Also

Reference

<exception>

get_unexpected