Diagnostics library - cppreference.com

From cppreference.com

Exception handling

The header

<exception>

provides several classes and functions related to exception handling in C++ programs.

Defined in header

<exception>

exception

base class for exceptions thrown by the standard library components
(class)

[edit]

Capture and storage of exception objects

uncaught_exceptionuncaught_exceptions

(removed in C++20*)(C++17)

checks if exception handling is currently in progress
(function)

[edit]

exception_ptr

(C++11)

shared pointer type for handling exception objects
(typedef)

[edit]

make_exception_ptr

(C++11)

creates an

std::exception_ptr

from an exception object
(function template)

[edit]

current_exception

(C++11)

captures the current exception in a

std::exception_ptr

(function)

[edit]

rethrow_exception

(C++11)

throws the exception from an

std::exception_ptr

(function)

[edit]

nested_exception

(C++11)

a mixin type to capture and store current exceptions
(class)

[edit]

throw_with_nested

(C++11)

throws its argument with

std::nested_exception

mixed in
(function template)

[edit]

rethrow_if_nested

(C++11)

throws the exception from a

std::nested_exception

(function template)

[edit]

Handling of failures in exception handling Defined in header

<exception>

terminate

function called when exception handling fails
(function)

[edit]

terminate_handler

the type of the function called by

std::terminate

(typedef)

[edit]

get_terminate

(C++11)

obtains the current terminate_handler
(function)

[edit]

set_terminate

changes the function to be called by

std::terminate

(function)

[edit]

bad_exception

exception thrown when

std::current_exception

fails to copy the exception object
(class)

[edit]

Handling of exception specification violations (until C++17)

unexpected

(deprecated in C++11)(removed in C++17)

function called when dynamic exception specification is violated
(function)

[edit]

unexpected_handler

(deprecated in C++11)(removed in C++17)

the type of the function called by

std::unexpected

(typedef)

[edit]

get_unexpected

(deprecated in C++11)(removed in C++17)

obtains the current unexpected_handler
(function)

[edit]

set_unexpected

(deprecated in C++11)(removed in C++17)

changes the function to be called by

std::unexpected

(function)

[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 cannot easily be predicted.

Defined in header

<stdexcept>

logic_error

exception class to indicate violations of logical preconditions or class invariants
(class)

[edit]

invalid_argument

exception class to report invalid arguments
(class)

[edit]

domain_error

exception class to report domain errors
(class)

[edit]

length_error

exception class to report attempts to exceed maximum allowed size
(class)

[edit]

out_of_range

exception class to report arguments outside of expected range
(class)

[edit]

runtime_error

exception class to indicate conditions only detectable at run time
(class)

[edit]

range_error

exception class to report range errors in internal computations
(class)

[edit]

overflow_error

exception class to report arithmetic overflows
(class)

[edit]

underflow_error

exception class to report arithmetic underflows
(class)

[edit]

tx_exception

(TM TS)

exception class to cancel atomic transactions
(class template)Error numbers

System error (since C++11)

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>

error_category

(C++11)

base class for error categories
(class)

[edit]

generic_category

(C++11)

identifies the generic error category
(function)

[edit]

system_category

(C++11)

identifies the operating system error category
(function)

[edit]

error_condition

(C++11)

holds a portable error code
(class)

[edit]

errc

(C++11)

the

std::error_condition

enumeration listing all standard

<cerrno>

macro constants
(class)

[edit]

error_code

(C++11)

holds a platform-dependent error code
(class)

[edit]

system_error

(C++11)

exception class used to report conditions that have an error_code
(class)

[edit]

Assertions

Assertions help to implement checking of preconditions in programs.

aborts the program if the user-specified condition is not true. May be disabled for release builds.
(function macro)

[edit]

Stacktrace

(since C++23)

Debugging support (since C++26)

See also