๐ 2014-Oct-09 โฌฉ โ๏ธ Ashwin Nanjappa โฌฉ ๐ท๏ธ cpp, exception, stdexcept โฌฉ ๐ Archive
All the standard exceptions in C++ are derived from the exception
class that is defined in the exception
header file. The standard exceptions are defined in the stdexcept
header file.
The hierarchy of standard exceptions is shown below using an ASCII tree:
exception
โโโ bad_alloc
โย ย โโโ bad_array_new_length
โโโ bad_cast
โโโ bad_exception
โโโ bad_typeid
โโโ logic_error
โย ย โโโ domain_error
โย ย โโโ future_error
โย ย โโโ invalid_argument
โย ย โโโ length_error
โย ย โโโ out_of_range
โโโ runtime_error
โโโ overflow_error
โโโ range_error
โโโ system_error
โย ย โโโ ios_base::failure
โโโ underflow_error
Typically, logic_error
, runtime_error
and their children are thrown in user code. These exceptions take a std::string
or string literal as input.
You cannot throw exception
or any of the language exceptions. You can however derive from the exception
class to create your own exception.
Reference: ยง30.4.1.1 in The C++ Programming Language (4 Ed) by Stroustrup