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.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

All Exception Transport and Termination Facilities

Exception transport helpers

Termination and handler control

Uncaught-exception state queries

Practical rules

Small worked example

#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.

Termination-hook rule

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.

Example in practice

#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);
    }
}