Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/error/unexpected handler"

From cppreference.com
< cpp‎ | error
m (Text replace - "cpp/error/exception" to "cpp/error")
m (Text replace - "/sidebar" to "/navbar")
Line 1: Line 1:
 
{{cpp/title|unexpected_handler}}
 
{{cpp/title|unexpected_handler}}
{{cpp/error/sidebar}}
+
{{cpp/error/navbar}}
 
{{ddcl list begin}}
 
{{ddcl list begin}}
 
{{ddcl list header | exception}}
 
{{ddcl list header | exception}}

Revision as of 12:35, 15 June 2012

 
 
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <exception>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
typedef void (*unexpected_handler)();
</td>

<td class="t-dcl-nopad"> </td> <td > (deprecated) </td> </tr> Template:ddcl list end

std::unexpected_handler is the function pointer type (pointer to function that takes no arguments and returns void), which is installed and queried by the functions std::set_unexpected and std::get_unexpected and called by std::unexpected.

The C++ implementation provides a default std::unexpected_handler function, which calls std::terminate(). If the null pointer value is installed (by means of std::set_terminate), the implementation may restore the default handler instead.

A user-defined std::unexpected_handler is expected to either terminate the program or throw an exception. If it throws an exception, one of the following three situations may be encountered:

1) the exception thrown by std::unexpected_handler satisfies the dynamic exception specification that was violated earlier. The new exception is allowed to escape the function and stack unwinding continues.

2) the exception thrown by std::unexpected_handler still violates the exception specification:

2a) however, the exception specification allows std::bad_exception: the thrown exception object is destroyed, and std::bad_exception is constructed by the C++ runtime and thrown instead.

2b) the exception specification does not allow std::bad_exception: std::terminate() is called.

See also

Template:cpp/error/dcl list unexpectedTemplate:cpp/error/dcl list set unexpectedTemplate:cpp/error/dcl list get unexpected