Function current_exception

poet::current_exception — Get an exception_ptr which holds the current exception.


exception_ptr current_exception();


current_exception() can be used inside a catch block to get a copy of the current exception. This is especially useful inside catch(...) blocks where there is no explicit parameter corresponding to the exception.

Due to the limitations of exception handling in C++, current_exception() does not work perfectly. Only exception types specifically known by the implementation are captured correctly. Exceptions derived from the known exceptions will be captured as the most derived base class which is a known exception. Other exceptions will only be captured as poet::unknown_exception objects. If current_exception() can only determine that the exception is derived from std::exception, then the exception will also be captured as a poet::unknown_exception, although it will capture the correct std::exception::what() string.

The implementation knows all the exceptions in <stdexcept>, as well as all the exception classes in libpoet and some of the exceptions specified in thread_safe_signals and boost.

libpoet uses current_exception() to transport an exception thrown by a passive function in a method request being run in a scheduler's thread back to a thread waiting on a future corresponding to the method request's return value.