Provides consistent interface to handle errors through thethrow expression.
All exceptions generated by the standard library inherit fromstd::exception
.
All member functions ofstd::exception areconstexpr. | (since C++26) |
[edit]Member functions
| constructs the exception object (public member function) |
| destroys the exception object (virtual public member function)[edit] |
| copies exception object (public member function)[edit] |
| returns an explanatory string (virtual public member function)[edit] |
[edit]Standard exception requirements
Each standard library classT
that derives fromstd::exception
has the following publicly accessible member functions, each of themdo not exit with an exception(until C++11)having anon-throwing exception specification(since C++11):
The copy constructor and the copy assignment operator meet the following postcondition:
- If two objectslhs andrhs both have dynamic type
T
andlhs is a copy ofrhs, thenstd::strcmp(lhs.what(), rhs.what()) is equal to0.
Thewhat()
member function of each suchT
satisfies the constraints specified forstd::exception::what().
[edit]Standard exceptions
[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 471 | C++98 | there was no requirement on standard library classes derived fromstd::exception | added |