Exceptions [C++ Reference]
Keywords: exception,start
Date: 2009-12-08T03:56:15-0800

## Exceptions

### Handling

The `<exception>` header provides functions and classes for exception control. One basic class is `exception`:

    class exception
    {
    public:
        exception() throw();
        exception(const exception&) throw();
        exception& operator=(const exception&) throw();
        virtual ~exception() throw();
        virtual const char *what() const throw();
    };

### Standard Exceptions

The `<stdexcept>` header provides a small hierarchy of exception classes that can be thrown or caught:

- `exception`
  - `logic_error`
    - `domain_error`
    - `invalid_argument`
    - `length_error`
    - `out_of_range`
  - `runtime_error`
    - `range_error`
    - `overflow_error`
    - `underflow_error`

Logic errors are thrown if the program has internal errors that are caused by the user of a function and that, in theory, are preventable.
Runtime errors are thrown if the cause is beyond the program and can't be predicted by the user of a function.