Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.

Boost Exception

exception_ptr

#include <boost/exception_ptr.hpp>

namespace
boost
    {
    typedef ---unspecified--- exception_ptr;
    }

The exception_ptr type can be used to refer to a copy of an exception object. It is Default Constructible, Copy Constructible, Assignable and Equality Comparable; exception_ptr's operations do not throw.

The referenced object remains valid at least as long as there is an exception_ptr object that refers to it.

Two instances of exception_ptr are equivalent and compare equal if and only if they refer to the same exception.

The default constructor of exception_ptr produces the null value of the type. The null value is equivalent only to itself.

Thread safety

  • It is legal for multiple threads to hold exception_ptr references to the same exception object.
  • It is illegal for multiple threads to modify the same exception_ptr object concurrently.
  • While calling current_exception makes a copy of the current exception object, it is still possible for the two copies to share internal state. Therefore, in general it is not safe to call rethrow_exception concurrently to throw the same exception object into multiple threads.

Nesting of exceptions:

An exception_ptr can be added as error_info to any boost::exception. This is a convenient way to nest exceptions. There is no limit on the depth of the nesting, however cyclic references result in undefined behavior.