All Exception Transport and Termination Facilities
All Exception Transport and Termination Facilities
A compact scan page for exception_ptr transport, nested exceptions, uncaught-exception queries, and termination handlers.
All Exception Transport and Termination Facilities
A compact scan page for exception_ptr transport, nested exceptions, uncaught-exception queries, and termination handlers.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::exception_ptrstd::current_exceptionstd::rethrow_exceptionstd::make_exception_ptrstd::nested_exceptionstd::throw_with_nestedstd::rethrow_if_nestedstd::terminatestd::set_terminatestd::get_terminatestd::terminate_handlerstd::uncaught_exceptionsstd::uncaught_exception in older codebasesexception_ptr when exceptions must cross thread or deferred-execution boundariesuncaught_exceptions() is mainly a low-level building block for transactional guards and rollback helpers#include <exception>
#include <iostream>
#include <thread>
int main() {
std::exception_ptr transported;
std::jthread worker([&] {
try {
throw std::runtime_error{"background parse failed"};
} catch (...) {
transported = std::current_exception();
}
});
if (transported) {
try {
std::rethrow_exception(transported);
} catch (const std::exception& ex) {
std::cerr << ex.what() << '\n';
}
}
}
Use this pattern when work happens elsewhere but the decision about logging, retrying, or failing the request belongs to the caller that launched it.
If you install a std::terminate handler, keep it limited to last-ditch logging or crash reporting. Do not allocate, throw, or depend on fragile global state inside that handler.
#include <exception>
#include <thread>
int main() {
std::exception_ptr transported;
std::jthread worker([&] {
try {
throw std::runtime_error{"worker failed"};
} catch (...) {
transported = std::current_exception();
}
});
if (transported) {
std::rethrow_exception(transported);
}
}