[exception] # 17 Language support library [[support]](./#support) ## 17.9 Exception handling [[support.exception]](support.exception#exception) ### 17.9.3 Class exception [exception] [🔗](#lib:exception) namespace std {class exception {public:constexpr exception() noexcept; constexpr exception(const exception&) noexcept; constexpr exception& operator=(const exception&) noexcept; constexpr virtual ~exception(); constexpr virtual const char* what() const noexcept; };} [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3893) The classexception defines the base class for the types of objects thrown as exceptions by C++ standard library components, and certain expressions, to report errors detected during program execution[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3901) Except where explicitly specified otherwise, each standard library class T that derives from class exception has the following publicly accessible member functions, each of them having a non-throwing exception specification ([[except.spec]](except.spec "14.5 Exception specifications")): - [(2.1)](#2.1) default constructor (unless the class synopsis shows other constructors) - [(2.2)](#2.2) copy constructor - [(2.3)](#2.3) copy assignment operator The copy constructor and the copy assignment operator meet the following postcondition: If two objects lhs and rhs both have dynamic type T and lhs is a copy of rhs, thenstrcmp(lhs.what(), rhs.what()) is equal to 0[.](#2.sentence-1) The what() member function of each such T satisfies the constraints specified for exception​::​what() (see below)[.](#2.sentence-2) [🔗](#lib:exception,constructor_) `constexpr exception(const exception& rhs) noexcept; constexpr exception& operator=(const exception& rhs) noexcept; ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3926) *Postconditions*: If *this and rhs both have dynamic type exception then the value of the expression strcmp(what(), rhs.what()) shall equal 0[.](#3.sentence-1) [🔗](#lib:exception,destructor) `constexpr virtual ~exception(); ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3938) *Effects*: Destroys an object of classexception[.](#4.sentence-1) [🔗](#lib:what,exception) `constexpr virtual const char* what() const noexcept; ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3950) *Returns*: An implementation-defined ntbs, which during constant evaluation is encoded with the ordinary literal encoding ([[lex.ccon]](lex.ccon "5.13.3 Character literals"))[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3956) *Remarks*: The message may be a[null-terminated multibyte string](multibyte.strings#def:ntmbs "16.3.3.3.4.3 Multibyte strings [multibyte.strings]"), suitable for conversion and display as awstring ([[string.classes]](string.classes "27.4 String classes"), [[locale.codecvt]](locale.codecvt "28.3.4.2.5 Class template codecvt"))[.](#6.sentence-1) The return value remains valid until the exception object from which it is obtained is destroyed or a non-const member function of the exception object is called[.](#6.sentence-2)