C++11 exception-handling improvements
C++11 introduced the ability to capture and store an exception that can be passed around and rethrown later. This is particularly useful for propagating exceptions across threads.
Storing and rethrowing exceptions
To store an exception, the type std::exception_ptr
is used. std::exception_ptr
is a smart pointer type with shared ownership semantics, not unlike std::shared_ptr
(see Chapter 3, Memory Management and Exception Safety). An instance of std::exception_ptr
is copyable and movable and can be passed to other functions potentially across threads. A default-constructed std::exception_ptr
is a null object that does not point to any exception. Copying a std::exception_ptr
object creates two instances that manage the same underlying exception object. The underlying exception object continues to exist as long as the last exception_ptr
instance containing it exists.
The function std::current_exception
, when called inside a catch-block, returns the active...