Class derived from exception exception Class derived from logic_error logic_error exception Class derived from runtime_error runtime_error exception
The C++ Standard Library exception classes
The C++ Standard Library defines a set of classes intended to be thrown as exceptions. Objects of these classes, and classes derived from these classes, are the only exceptions that can be thrown by the Library. In contrast, client code can throw not only objects of the exception classes, but objects of any type, including native types. The description of each exception class in this entry lists the classes and functions that typically throw it, but exceptions may be thrown from other places as well.
The class exception serves as a base class to all other Standard exception classes. The Library has three categories of exception classes:
classes derived directly from exception
classes derived through logic_error
classes derived through runtime_error
The diagram above shows the public hierarchy for all derived classes.
The classes derived directly from exception are:
The classes derived from logic_error are:
The classes derived from runtime_error are:
A logic_error is thrown when the condition causing the error could have been detected by the client before calling the failing code. A runtime_error is thrown when the error results from a condition that the client could not have tested before calling the failing code.
The class exception is declared in the header <exception>. Exception classes derived from logic_error and runtime_error are defined in the <stdexcept> header. The remaining exception classes are defined in various other headers.
bad_alloc, bad_cast, bad_exception, bad_typeid, domain_error, exception, invalid_argument, ios_base::failure, length_error, logic_error, out_of_range, overflow_error, range_error, runtime_error, underflow_error
ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Section 19.1