Standard Exceptions and Errors
Standard Exceptions and Errors
The main C++ exception families, error-code facilities, and adjacent C error-reporting mechanisms.
Standard Exceptions and Errors
The main C++ exception families, error-code facilities, and adjacent C error-reporting mechanisms.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
At the broadest level, most standard exceptions derive from std::exception.
std::exceptionstd::bad_exceptionstd::nested_exceptionTypes from <stdexcept> that usually represent programming mistakes or invalid use:
std::logic_errorstd::invalid_argumentstd::domain_errorstd::length_errorstd::out_of_rangeTypes from <stdexcept> that usually represent failures discovered during execution:
std::runtime_errorstd::range_errorstd::overflow_errorstd::underflow_errorstd::bad_allocstd::bad_array_new_lengthstd::bad_caststd::bad_typeidstd::bad_function_callstd::bad_variant_accessstd::bad_optional_accessstd::bad_expected_access<E>std::bad_any_caststd::filesystem::filesystem_errorstd::system_errorstd::error_codestd::error_conditionstd::error_categorystd::errcstd::exception_ptrstd::current_exceptionstd::rethrow_exceptionstd::make_exception_ptrWhen working closer to C APIs or POSIX-style interfaces, you will also see:
errnoperrorstrerrorstd::error_code when a non-throwing API is part of the design.std::expected<T, E> instead of throwing from local, expected failure paths.int main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}