MFC Programmer's SourceBook : Thinking in C++
Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Standard exceptions

The set of exceptions used with the Standard C++ library are also available for your own use. Generally it’s easier and faster to start with a standard exception class than to try to define your own. If the standard class doesn’t do what you need, you can derive from it.

The following tables describe the standard exceptions:

exception

The base class for all the exceptions thrown by the C++ standard library. You can ask what( ) and get a result that can be displayed as a character representation.

logic_error

Derived from exception. Reports program logic errors, which could presumably be detected before the program executes.

runtime_error

Derived from exception. Reports run-time errors, which can presumably be detected only when the program executes.

The iostream exception class ios::failure is also derived from exception, but it has no further subclasses.

The classes in both of the following tables can be used as they are, or they can act as base classes to derive your own more specific types of exceptions.

Exception classes derived from logic_error

domain_error

Reports violations of a precondition.

invalid_argument

Indicates an invalid argument to the function it’s thrown from.

length_error

Indicates an attempt to produce an object whose length is greater than or equal to NPOS (the largest representable value of type size_t).

out_of_range

Reports an out-of-range argument.

bad_cast

Thrown for executing an invalid dynamic_cast expression in run-time type identification (see Chapter 17).

bad_typeid

Reports a null pointer p in an expression typeid(*p). (Again, a run-time type identification feature in Chapter 17).

Exception classes derived from runtime_error

range_error

Reports violation of a postcondition.

overflow_error

Reports an arithmetic overflow.

bad_alloc

Reports a failure to allocate storage.

Contents | Prev | Next


Go to CodeGuru.com
Contact: webmaster@codeguru.com
© Copyright 1997-1999 CodeGuru