Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/error"

From cppreference.com
< cpp
(+tx_exception (here because TS puts it in <stdexcept>))
(~ -> diagnostics library + add debugging)
 
(13 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{title|Error handling}}
+
{{title|Diagnostics library}}
 
{{cpp/error/navbar}}
 
{{cpp/error/navbar}}
  
 
===Exception handling===
 
===Exception handling===
The header {{tt|<exception>}} provides several classes and functions related to exception handling in C++ programs.
+
The header {{header|exception}} provides several classes and functions related to exception handling in C++ programs.
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | exception}}
+
{{dsc header|exception}}
{{dsc inc | cpp/error/dsc exception}}
+
{{dsc inc|cpp/error/dsc exception}}
{{dsc h2 | Capture and storage of exception objects}}
+
{{dsc h2|Capture and storage of exception objects}}
{{dsc inc | cpp/error/dsc uncaught_exception}}
+
{{dsc inc|cpp/error/dsc uncaught_exception}}
{{dsc inc | cpp/error/dsc exception_ptr}}
+
{{dsc inc|cpp/error/dsc exception_ptr}}
{{dsc inc | cpp/error/dsc make_exception_ptr}}
+
{{dsc inc|cpp/error/dsc make_exception_ptr}}
{{dsc inc | cpp/error/dsc current_exception}}
+
{{dsc inc|cpp/error/dsc current_exception}}
{{dsc inc | cpp/error/dsc rethrow_exception}}
+
{{dsc inc|cpp/error/dsc rethrow_exception}}
{{dsc inc | cpp/error/dsc nested_exception}}
+
{{dsc inc|cpp/error/dsc nested_exception}}
{{dsc inc | cpp/error/dsc throw_with_nested}}
+
{{dsc inc|cpp/error/dsc throw_with_nested}}
{{dsc inc | cpp/error/dsc rethrow_if_nested}}
+
{{dsc inc|cpp/error/dsc rethrow_if_nested}}
{{dsc header | exception_list}}
+
{{dsc h2|Handling of failures in exception handling}}
{{dsc inc | cpp/error/dsc exception_list}}
+
{{dsc header|exception}}
{{dsc h2 | Handling of failures in exception handling}}
+
{{dsc inc|cpp/error/dsc terminate}}
{{dsc header | exception}}
+
{{dsc inc|cpp/error/dsc terminate_handler}}
{{dsc inc | cpp/error/dsc terminate}}
+
{{dsc inc|cpp/error/dsc get_terminate}}
{{dsc inc | cpp/error/dsc terminate_handler}}
+
{{dsc inc|cpp/error/dsc set_terminate}}
{{dsc inc | cpp/error/dsc get_terminate}}
+
{{dsc inc|cpp/error/dsc bad_exception}}
{{dsc inc | cpp/error/dsc set_terminate}}
+
{{dsc h2|Handling of exception specification violations {{mark until c++17|removed=yes}}}}
{{dsc h2 | Handling of exception specification violations}}
+
{{dsc inc|cpp/error/dsc unexpected}}
{{dsc inc | cpp/error/dsc unexpected}}
+
{{dsc inc|cpp/error/dsc unexpected_handler}}
{{dsc inc | cpp/error/dsc bad_exception}}
+
{{dsc inc|cpp/error/dsc get_unexpected}}
{{dsc inc | cpp/error/dsc unexpected_handler}}
+
{{dsc inc|cpp/error/dsc set_unexpected}}
{{dsc inc | cpp/error/dsc get_unexpected}}
+
{{dsc inc | cpp/error/dsc set_unexpected}}
+
 
{{dsc end}}
 
{{dsc end}}
  
====Exception categories====
+
===Exception categories===
 
+
Several convenience classes are predefined in the header {{tt|<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.
Several convenience classes are predefined in the header {{tt|<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.
+
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | stdexcept}}
+
{{dsc header|stdexcept}}
{{dsc class | cpp/error/logic_error | exception class to indicate violations of logical preconditions or class invariants}}
+
{{dsc inc|cpp/error/inc logic_error}}
{{dsc class | cpp/error/invalid_argument | exception class to report invalid arguments}}
+
{{dsc inc|cpp/error/inc invalid_argument}}
{{dsc class | cpp/error/domain_error | exception class to report domain errors}}
+
{{dsc inc|cpp/error/inc domain_error}}
{{dsc class | cpp/error/length_error | exception class to report attempts to exceed maximum allowed size}}
+
{{dsc inc|cpp/error/inc length_error}}
{{dsc class | cpp/error/out_of_range | exception class to report arguments outside of expected range}}
+
{{dsc inc|cpp/error/inc out_of_range}}
{{dsc class | cpp/error/runtime_error | exception class to indicate conditions only detectable at run time}}
+
{{dsc inc|cpp/error/inc runtime_error}}
{{dsc class | cpp/error/range_error | exception class to report range errors in internal computations}}
+
{{dsc inc|cpp/error/inc range_error}}
{{dsc class | cpp/error/overflow_error | exception class to report arithmetic overflows}}
+
{{dsc inc|cpp/error/inc overflow_error}}
{{dsc class | cpp/error/underflow_error | exception class to report arithmetic underflows}}
+
{{dsc inc|cpp/error/inc underflow_error}}
{{dsc class | cpp/error/tx_exception | exception class to cancel atomic transacations|notes={{mark since tm ts}}}}
+
{{dsc tclass|cpp/error/tx_exception|exception class to cancel atomic transactions|notes={{mark since tm ts}}}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Error numbers===
 
===Error numbers===
 +
{{dsc begin}}
 +
{{dsc header|cerrno}}
 +
{{dsc inc|cpp/error/dsc errno}}
 +
{{dsc inc|cpp/error/dsc errno_macros}}
 +
{{dsc end}}
 +
 +
===System error===
 +
The header {{tt|<system_error>}} defines types and functions used to report error conditions originating from the operating system, streams I/O, {{lc|std::future}}, or other low-level APIs.
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | cerrno}}
+
{{dsc header|system_error}}
{{dsc inc | cpp/error/dsc errno}}
+
{{dsc inc|cpp/error/dsc error_category}}
{{dsc inc | cpp/error/dsc errno_macros}}
+
{{dsc inc|cpp/error/dsc generic_category}}
 +
{{dsc inc|cpp/error/dsc system_category}}
 +
{{dsc inc|cpp/error/dsc error_condition}}
 +
{{dsc inc|cpp/error/dsc errc}}
 +
{{dsc inc|cpp/error/dsc error_code}}
 +
{{dsc inc|cpp/error/dsc system_error}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Assertions===
 
===Assertions===
 
 
Assertions help to implement checking of preconditions in programs.
 
Assertions help to implement checking of preconditions in programs.
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/language/dsc static_assert}}
+
{{dsc header|cassert}}
{{dsc break}}
+
{{dsc inc|cpp/error/dsc assert}}
{{dsc header | cassert}}
+
{{dsc inc | cpp/error/dsc assert}}
+
 
{{dsc end}}
 
{{dsc end}}
  
===System error===
+
===[[cpp/utility/basic_stacktrace|Stacktrace]]===
 
+
{{dsc begin}}
The header {{tt|<system_error>}} defines types and functions used to report error conditions originating from the operating system, streams I/O, {{lc|std::future}}, or other low-level APIs.
+
{{dsc header|stacktrace}}
 +
{{dsc inc|cpp/utility/dsc stacktrace_entry}}
 +
{{dsc inc|cpp/utility/dsc basic_stacktrace}}
 +
{{dsc end}}
  
 +
===Debugging support===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc header | system_error}}
+
{{dsc header|debugging}}
{{dsc inc | cpp/error/dsc error_category}}
+
{{dsc inc|cpp/utility/dsc breakpoint}}
{{dsc inc | cpp/error/dsc generic_category}}
+
{{dsc inc|cpp/utility/dsc breakpoint_if_debugging}}
{{dsc inc | cpp/error/dsc system_category}}
+
{{dsc inc|cpp/utility/dsc is_debugger_present}}
{{dsc inc | cpp/error/dsc error_condition}}
+
{{dsc inc | cpp/error/dsc errc}}
+
{{dsc inc | cpp/error/dsc error_code}}
+
{{dsc inc | cpp/error/dsc system_error}}
+
 
{{dsc end}}
 
{{dsc end}}
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc see c | c/error | Error handling}}
+
{{dsc inc|cpp/language/dsc static_assert}}
 +
{{dsc see c|c/error|Error handling|nomono=true}}
 
{{dsc end}}
 
{{dsc end}}
  
 
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
 
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 20:54, 30 October 2024

 
 
 

Contents

[edit] 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 (removed in 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]

[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) [edit]
exception class to report domain errors
(class) [edit]
exception class to report attempts to exceed maximum allowed size
(class) [edit]
exception class to report arguments outside of expected range
(class) [edit]
exception class to indicate conditions only detectable at run time
(class) [edit]
exception class to report range errors in internal computations
(class) [edit]
exception class to report arithmetic overflows
(class) [edit]
exception class to report arithmetic underflows
(class) [edit]
exception class to cancel atomic transactions
(class template)

[edit] Error numbers

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

[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
(class) [edit]
identifies the generic error category
(function) [edit]
identifies the operating system error category
(function) [edit]
holds a portable error code
(class) [edit]
(C++11)
the std::error_condition enumeration listing all standard <cerrno> macro constants
(class) [edit]
holds a platform-dependent error code
(class) [edit]
exception class used to report conditions that have an error_code
(class) [edit]

[edit] Assertions

Assertions help to implement checking of preconditions in programs.

Defined in header <cassert>
aborts the program if the user-specified condition is not true. May be disabled for release builds.
(function macro) [edit]

[edit] Stacktrace

Defined in header <stacktrace>
representation of an evaluation in a stacktrace
(class) [edit]
approximate representation of an invocation sequence consists of stacktrace entries
(class template) [edit]

[edit] Debugging support

Defined in header <debugging>
pauses the running program when called
(function) [edit]
calls std::breakpoint if std::is_debugger_present returns true
(function) [edit]
checks whether a program is running under the control of a debugger
(function) [edit]

[edit] See also

static_assert declaration (C++11) performs compile-time assertion checking[edit]
C documentation for Error handling