Error handling

< cpp
Error handling
Exception handling
exception_ptr (C++11)
make_exception_ptr (C++11)
current_exception (C++11)
rethrow_exception (C++11)
nested_exception (C++11)
throw_with_nested (C++11)
rethrow_if_nested (C++11)
Exception handling failures
get_terminate (C++11)
unexpected (deprecated)
unexpected_handler (deprecated)
get_unexpected (C++11)(deprecated)
set_unexpected (deprecated)
Exception categories
Error codes
Error codes
system_error facility
error_category (C++11)
generic_category (C++11)
system_category (C++11)
error_condition (C++11)
errc (C++11)
error_code (C++11)
system_error (C++11)


[edit] Exception handling

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

Defined in header <exception>
base class for exceptions thrown by the standard library components
Capture and storage of exception objects
checks if exception handling is currently in progress
shared pointer type for handling exception objects
creates an std::exception_ptr from an exception object
(function template)
captures the current exception in a std::exception_ptr
throws the exception from an std::exception_ptr
a mixin type to capture and store current exceptions
throws its argument with std::nested_exception mixed in
(function template)
throws the exception from a std::nested_exception
(function template)
Handling of failures in exception handling
function called when exception handling fails
the type of the function called by std::terminate
obtains the current terminate_handler
changes the function to be called by std::terminate
Handling of exception specification violations
function called when dynamic exception specification is violated
exception thrown when dynamic exception specification is violated, if possible
the type of the function called by std::unexpected
obtains the current unexpected_handler
changes the function to be called by std::unexpected

[edit] 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

[edit] Error numbers

Defined in header <cerrno>
macro which expands to POSIX-compatible thread-local error number variable
(macro variable)
macros for standard POSIX-compatible error conditions
(macro constant)

[edit] Assertions

Assertions help to implement checking of preconditions in programs.

static assertion performs compile-time assertion checking (since C++11)
Defined in header <cassert>
aborts the program if the user-specified condition is not true. May be disabled for release builds
(function macro)

[edit] 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.

Defined in header <system_error>
base class for error categories
identifies the generic error category
identifies the operating system error category
holds a portable error code
the std::error_condition enumeration listing all standard <cerrno> macro constants
holds a platform-dependent error code
exception class used to report conditions that have an error_code