Files
cppdraft_translate/cppdraft/exception.md
2025-10-25 03:02:53 +03:00

3.4 KiB
Raw Permalink Blame History

[exception]

17 Language support library [support]

17.9 Exception handling [support.exception]

17.9.3 Class exception [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

#

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.

2

#

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]):

default constructor (unless the class synopsis shows other constructors)

copy constructor

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.

The what() member function of each such T satisfies the constraints specified for exception::what() (see below).

🔗

constexpr exception(const exception& rhs) noexcept; constexpr exception& operator=(const exception& rhs) noexcept;

3

#

Postconditions: If *this and rhs both have dynamic type exception then the value of the expression strcmp(what(), rhs.what()) shall equal 0.

🔗

constexpr virtual ~exception();

4

#

Effects: Destroys an object of classexception.

🔗

constexpr virtual const char* what() const noexcept;

5

#

Returns: An implementation-defined ntbs, which during constant evaluation is encoded with the ordinary literal encoding ([lex.ccon]).

6

#

Remarks: The message may be anull-terminated multibyte string, suitable for conversion and display as awstring ([string.classes], [locale.codecvt]).

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.