Standard exception classes in C ++
Namespace std
{
// Exception Derivation
Class logic_error; // logical error, which can be detected before running the program.
// Logic_error is derived.
Class domain_error; // The precondition is violated.
Class invalid_argument; // specifies an invalid parameter of the function.
Class length_error; // an attempt to point out an object that exceeds the maximum value of the present value of the size_t type
Class out_of_range; // parameter out of bounds
Class bad_cast; // an invalid dynamic_cast expression exists in the runtime type recognition.
Class bad_typeid; // report has a null pointer P in expression test typeid (* P)
// Exception Derivation
Class runtime_error; // runtime error, detected only during program running
// Runtime_error Derivation
Class range_error; // violates the post Condition
Class overflow_error; // report an arithmetic Overflow
Class bad_alloc; // Storage Allocation Error
}
Observe the hierarchy of the above classes. We can see that all standard exceptions are derived from a common base class exception. The base class contains necessary polymorphism functions that provide exception descriptions and can be overloaded. The following is the prototype of the exception class:
Class exception
{
Public:
Exception () Throw ();
Exception (const exception & RHs) Throw ();
Exception & operator = (const exception & RHs) Throw ();
Virtual ~ Exception () Throw ();
Virtual const char * What () const throw ();
};
One of the important functions is what (), which returns a string pointer indicating an exception.