Processing exceptions is not always trivial and may consume a lot of time. Consider the situation when an exception must be serialized and sent by the network. This may take milliseconds and a few thousands of lines of code. After the exception is caught, it is not always the best time and place to process it.
Can we store exceptions and delay their processing?
This recipe requires familiarity with boost::asio::io_service
, which was described in the first recipe of this chapter.
This recipe requires linking with the boost_system
and boost_thread
libraries.
All we need is to have an ability to store exceptions and pass them between threads just like a usual variable.
- Let's start with the function that stores and processes exceptions:
#include <boost/exception_ptr.hpp> struct process_exception { boost::exception_ptr exc_; explicit process_exception(const boost::exception_ptr& exc) : exc_(exc) ...