std::exception_ptr

Exception pointer

Smart pointer type that can refer to exception objects.

It is a shared pointer-like type: The pointed exception is guaranteed to remain valid for as long as at least one exception_ptr points to it, potentially extending its lifetime beyond the scope of a catch statement or across threads.

Different libraries may implement this type differently, but it shall at least support the following operations without throwing:

Being default-constructed (acquiring a null-pointer value).

Being copied, including being copied a null-pointer value (or nullptr).

Being compared against another exception_ptr object (or nullptr) using either operator== or operator!=, where two null-pointers are always considered equivalent, and two non-null pointers are considered equivalent only if they refer to the same exception object.

Being contextually convertible to bool, as false if having null-pointer value, and as true otherwise.

Being swapped, and being destructed.

The type is also required to not be implicitly convertible to an arithmetic, enumeration, or pointer type.

Performing any other operation on the object (such as dereferencing it), if at all supported by the library implementation, causes undefined behavior.