exception:start

C++ Reference

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 in theory preventable.
Runtime errors are thrown if the cause is beyond the program and can't be predict by user of a function.