Friday, September 3, 2010

std::exception

throw std::exception("my bad"); does not compile, but throw std::out_of_range("too big"); does.

std::exception can be derived from, but cannot be thrown directly. It is the base class for all of the C++ Standard Library exceptions. Here is the exception hierarchy:
exception
        bad_alloc
        bad_cast
        bad_exception
        bad_typeid
        io_base::failure
        logic_error
            domain_error
            invalid_argument
            length_error
            out_of_range
        runtime_error
            overflow_error
            range_error
            underflow_error
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 30.

No comments:

Post a Comment