Namespaces
Variants

Diagnostics library

From cppreference.com
< cpp
Revision as of 19:35, 28 January 2025 by YexuanXiao (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 

Exception handling

The header <exception> provides 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
(class) [edit]
Capture and storage of exception objects
(removed in C++20*)(C++17)
checks if exception handling is currently in progress
(function) [edit]
shared pointer type for handling exception objects
(typedef) [edit]
creates an std::exception_ptr from an exception object
(function template) [edit]
captures the current exception in a std::exception_ptr
(function) [edit]
throws the exception from an std::exception_ptr
(function) [edit]
a mixin type to capture and store current exceptions
(class) [edit]
throws its argument with std::nested_exception mixed in
(function template) [edit]
throws the exception from a std::nested_exception
(function template) [edit]
Handling of failures in exception handling
Defined in header <exception>
function called when exception handling fails
(function) [edit]
the type of the function called by std::terminate
(typedef) [edit]
obtains the current terminate_handler
(function) [edit]
changes the function to be called by std::terminate
(function) [edit]
exception thrown when std::current_exception fails to copy the exception object
(class) [edit]
Handling of exception specification violations (until C++17)
(deprecated in C++11)(removed in C++17)
function called when dynamic exception specification is violated
(function) [edit]
(deprecated in C++11)(removed in C++17)
the type of the function called by std::unexpected
(typedef) [edit]
(deprecated in C++11)(removed in C++17)
obtains the current unexpected_handler
(function) [edit]
(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>
exception class to indicate violations of logical preconditions or class invariants
(class) [edit]
exception class to report invalid arguments
(class)