Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

set_unexpected (<exception>)

 

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


   unexpected_handler
set_unexpected(
   unexpected_handler fnew
) throw( );

fnew

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

The address of the previous unexpected_handler.

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
}

My unhandled exception function called.

Requirements

Header: <exception>

Namespace: std

Show:
© 2016 Microsoft