![]() |
boost::scope::exception_checker — A predicate for checking whether an exception is being thrown.
// In header: <boost/scope/exception_checker.hpp> class exception_checker { public: // types typedef bool result_type; // Predicate result type. // public member functions exception_checker() noexcept; result_type operator()() const noexcept; };
On construction, the predicate captures the current number of uncaught exceptions, which it then compares with the number of uncaught exceptions at the point when it is called. If the number increased then a new exception is detected and the predicate returns true
.
![]() |
Note |
---|---|
This predicate is designed for a specific use case with scope guards created on the stack. It is incompatible with C++20 coroutines and similar facilities (e.g. fibers and userspace context switching), where the thread of execution may be suspended after the predicate captures the number of uncaught exceptions and then resumed in a different context, where the number of uncaught exceptions has changed. Similarly, it is incompatible with usage patterns where the predicate is cached after construction and is invoked after the thread has left the scope where the predicate was constructed (e.g. when the predicate is stored as a class data member or a namespace-scope variable). |
exception_checker
public member functionsexception_checker() noexcept;Constructs the predicate.
Upon construction, the predicate saves the current number of uncaught exceptions. This information will be used when calling the predicate to detect if a new exception is being thrown.
Throws: Nothing.
result_type operator()() const noexcept;Checks if an exception is being thrown.
Throws: Nothing.
Returns: |
|