19 Diagnostics library [diagnostics]

19.2 Exception classes [std.exceptions]

19.2.1 General [std.exceptions.general]

The C++ standard library provides classes to be used to report certain errors ([res.on.exception.handling]) in C++ programs.
In the error model reflected in these classes, errors are divided into two broad categories: logic errors and runtime errors.
The distinguishing characteristic of logic errors is that they are due to errors in the internal logic of the program.
In theory, they are preventable.
By contrast, runtime errors are due to events beyond the scope of the program.
They cannot be easily predicted in advance.
The header <stdexcept> defines several types of predefined exceptions for reporting errors in a C++ program.
These exceptions are related by inheritance.

19.2.2 Header <stdexcept> synopsis [stdexcept.syn]

namespace std { class logic_error; class domain_error; class invalid_argument; class length_error; class out_of_range; class runtime_error; class range_error; class overflow_error; class underflow_error; }

19.2.3 Class logic_error [logic.error]

namespace std { class logic_error : public exception { public: constexpr explicit logic_error(const string& what_arg); constexpr explicit logic_error(const char* what_arg); }; }
The class logic_error defines the type of objects thrown as exceptions to report errors presumably detectable before the program executes, such as violations of logical preconditions or class invariants.
constexpr logic_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr logic_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.4 Class domain_error [domain.error]

namespace std { class domain_error : public logic_error { public: constexpr explicit domain_error(const string& what_arg); constexpr explicit domain_error(const char* what_arg); }; }
The class domain_error defines the type of objects thrown as exceptions by the implementation to report domain errors.
constexpr domain_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr domain_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.5 Class invalid_argument [invalid.argument]

namespace std { class invalid_argument : public logic_error { public: constexpr explicit invalid_argument(const string& what_arg); constexpr explicit invalid_argument(const char* what_arg); }; }
The class invalid_argument defines the type of objects thrown as exceptions to report an invalid argument.
constexpr invalid_argument(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr invalid_argument(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.6 Class length_error [length.error]

namespace std { class length_error : public logic_error { public: constexpr explicit length_error(const string& what_arg); constexpr explicit length_error(const char* what_arg); }; }
The class length_error defines the type of objects thrown as exceptions to report an attempt to produce an object whose length exceeds its maximum allowable size.
constexpr length_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr length_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.7 Class out_of_range [out.of.range]

namespace std { class out_of_range : public logic_error { public: constexpr explicit out_of_range(const string& what_arg); constexpr explicit out_of_range(const char* what_arg); }; }
The class out_of_range defines the type of objects thrown as exceptions to report an argument value not in its expected range.
constexpr out_of_range(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr out_of_range(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.8 Class runtime_error [runtime.error]

namespace std { class runtime_error : public exception { public: constexpr explicit runtime_error(const string& what_arg); constexpr explicit runtime_error(const char* what_arg); }; }
The class runtime_error defines the type of objects thrown as exceptions to report errors presumably detectable only when the program executes.
constexpr runtime_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr runtime_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.9 Class range_error [range.error]

namespace std { class range_error : public runtime_error { public: constexpr explicit range_error(const string& what_arg); constexpr explicit range_error(const char* what_arg); }; }
The class range_error defines the type of objects thrown as exceptions to report range errors in internal computations.
constexpr range_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr range_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.10 Class overflow_error [overflow.error]

namespace std { class overflow_error : public runtime_error { public: constexpr explicit overflow_error(const string& what_arg); constexpr explicit overflow_error(const char* what_arg); }; }
The class overflow_error defines the type of objects thrown as exceptions to report an arithmetic overflow error.
constexpr overflow_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr overflow_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.

19.2.11 Class underflow_error [underflow.error]

namespace std { class underflow_error : public runtime_error { public: constexpr explicit underflow_error(const string& what_arg); constexpr explicit underflow_error(const char* what_arg); }; }
The class underflow_error defines the type of objects thrown as exceptions to report an arithmetic underflow error.
constexpr underflow_error(const string& what_arg);
Postconditions: strcmp(what(), what_arg.c_str()) == 0.
constexpr underflow_error(const char* what_arg);
Postconditions: strcmp(what(), what_arg) == 0.