August 2017
Intermediate to advanced
438 pages
14h 19m
English
Usually, exception_ptr is used to pass exceptions between threads. For example:
void run_throw(boost::exception_ptr& ptr) { try { // A lot of code goes here. } catch (...) { ptr = boost::current_exception(); }}int main () { boost::exception_ptr ptr; // Do some work in parallel. boost::thread t( &run_throw, boost::ref(ptr) ); // Some code goes here. // ... t.join(); // Checking for exception. if (ptr) { // Exception occurred in thread. boost::rethrow_exception(ptr); }}
The boost::exception_ptr class may allocate memory through heap multiple times, uses atomics, and implements some of the operations by re-throwing and catching exceptions. Try not to use it without an actual need.
C++11 has adopted boost::current_exception, ...
Read now
Unlock full access