Difference between revisions of "cpp/error/unexpected"
Andreas Krug (Talk | contribs) m (fmt, .) |
YexuanXiao (Talk | contribs) m |
||
(One intermediate revision by one user not shown) | |||
Line 7: | Line 7: | ||
void unexpected(); | void unexpected(); | ||
}} | }} | ||
− | {{dcl| | + | {{dcl|deprecated=c++11|until=c++17| |
[[noreturn]] void unexpected(); | [[noreturn]] void unexpected(); | ||
}} | }} | ||
Line 13: | Line 13: | ||
{{dcl end}} | {{dcl end}} | ||
− | {{tt|std::unexpected()}} is called by the C++ runtime when a [[cpp/language/ | + | {{tt|std::unexpected()}} is called by the C++ runtime when a [[cpp/language/except spec|dynamic exception specification]] is violated: an exception is thrown from a function whose exception specification forbids exceptions of this type. |
{{tt|std::unexpected()}} may also be called directly from the program. | {{tt|std::unexpected()}} may also be called directly from the program. | ||
Line 27: | Line 27: | ||
}} | }} | ||
{{rev end}} | {{rev end}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===Exceptions=== | ===Exceptions=== | ||
Line 39: | Line 33: | ||
===Defect reports=== | ===Defect reports=== | ||
{{dr list begin}} | {{dr list begin}} | ||
− | {{dr list item|wg=lwg|dr=2111|std=C++11|before=effect of calling {{ | + | {{dr list item|wg=lwg|dr=2111|std=C++11|before=effect of calling {{lc|std::set_unexpected}} during stack<br>unwinding differs from C++98 and breaks some ABIs|after=made unspecified}} |
{{dr list end}} | {{dr list end}} | ||
Latest revision as of 03:48, 20 August 2024
Defined in header <exception>
|
||
void unexpected(); |
(until C++11) | |
[[noreturn]] void unexpected(); |
(deprecated in C++11) (removed in C++17) |
|
std::unexpected()
is called by the C++ runtime when a dynamic exception specification is violated: an exception is thrown from a function whose exception specification forbids exceptions of this type.
std::unexpected()
may also be called directly from the program.
In either case, std::unexpected
calls the currently installed std::unexpected_handler. The default std::unexpected_handler calls std::terminate.
If a destructor reset the unexpected handler during stack unwinding and the unwinding later led to |
(until C++11) |
If a destructor reset the unexpected handler during stack unwinding, it is unspecified which handler is called if the unwinding later led to |
(since C++11) |
[edit] Exceptions
Throw any exception thrown by the currently installed std::unexpected_handler.
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2111 | C++11 | effect of calling std::set_unexpected during stack unwinding differs from C++98 and breaks some ABIs |
made unspecified |
[edit] See also
(C++23) |
represented as an unexpected value (class template) |
(deprecated in C++11)(removed in C++17) |
the type of the function called by std::unexpected (typedef) |