Exceptions in the standard library

Comparing to Java language C++ has only a few standard exception class. User programs can derive their own exception classes to express specific exceptions. Here we present the standard exceptions.


class exception {};                         // <exception>
class bad_alloc  : public exception {};     // new  <new>
class bad_cast   : public exception {};     // dynamic_cast
class bad_typeid : public exception {};     // typeid(0)
class ios_base::failure : public exception {};  // unexpected() <ios>
class bad_exception : public exception {};  // unexpected()

class runtime_error : public exception {};  // math. computation

class range_error     : public runtime_error {};
class overflow_error  : public runtime_error {};
class underflow_error : public runtime_error {};

class logic_error : public exception {};

class domain_error : public logic_error {}; // domain error
class invalid_argument : public logic_error {}; // bitset char != 0 or 1
class length_error : public logic_error {}; // std::string length exceeded
class out_of_range : public logic_error {}; // bad index in cont. or string


namespace std
{
    class exception
    {
    public:
        virtual const char *what() const throw();
        ...
    };
}