Error handling

< cpp
Revision as of 17:01, 2 November 2012 by P12bot (Talk | contribs)

Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
Relational operators
Optional and any
Pairs and tuples
Swap, forward and move
Type operations


Exception handling

The header <exception> provides several classes and functions related to exception handling in C++ programs.

Template:cpp/error/dcl list exceptionTemplate:cpp/error/dcl list uncaught exceptionTemplate:cpp/error/dcl list exception ptrTemplate:cpp/error/dcl list make exception ptrTemplate:cpp/error/dcl list current exceptionTemplate:cpp/error/dcl list rethrow exceptionTemplate:cpp/error/dcl list nested exceptionTemplate:cpp/error/dcl list throw with nestedTemplate:cpp/error/dcl list rethrow if nestedTemplate:cpp/error/dcl list terminateTemplate:cpp/error/dcl list terminate handlerTemplate:cpp/error/dcl list get terminateTemplate:cpp/error/dcl list set terminateTemplate:cpp/error/dcl list unexpectedTemplate:cpp/error/dcl list bad exceptionTemplate:cpp/error/dcl list unexpected handlerTemplate:cpp/error/dcl list get unexpectedTemplate:cpp/error/dcl list set unexpected
Defined in header <exception>
Capture and storage of exception objects
Handling of failures in exception handling
Handling of exception specification violations

Exception categories

Several convenience classes are predefined in the header <stdexcept> to report particular error conditions. These classes can be divided into two categories: logic errors and runtime errors. Logic errors are a consequence of faulty logic within the program and may be preventable. Runtime errors are due to events beyond the scope of the program and can not be easily predicted.

Defined in header <stdexcept>
exception class to indicate violations of logical preconditions or class invariants
exception class to report invalid arguments
exception class to report domain errors
exception class to report attempts to exceed maximum allowed size
exception class to report arguments outside of expected range
exception class to indicate conditions only detectable at run time
exception class to report range errors in internal computations
exception class to report arithmetic overflows
exception class to report arithmetic underflows

Error numbers

Template:cpp/error/dcl list errnoTemplate:cpp/error/dcl list errno macros
Defined in header <cerrno>


Assertions help to implement checking of preconditions in programs.

Template:cpp/language/dcl list static assert
Template:cpp/error/dcl list assert
Defined in header <cassert>

System error

The header <system_error> defines types and functions used to report error conditions originating from the operating system, streams I/O, std::future, or other low-level APIs.

Template:cpp/error/dcl list error categoryTemplate:cpp/error/dcl list generic categoryTemplate:cpp/error/dcl list system categoryTemplate:cpp/error/dcl list error conditionTemplate:cpp/error/dcl list errcTemplate:cpp/error/dcl list error codeTemplate:cpp/error/dcl list system error
Defined in header <system_error>