1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
2 
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 //This example shows how to transport cloning-enabled boost::exceptions between threads.
7 
8 #include <boost/exception_ptr.hpp>
9 #include <boost/thread.hpp>
10 #include <boost/bind.hpp>
11 
12 void do_work(); //throws cloning-enabled boost::exceptions
13 
14 void
worker_thread(boost::exception_ptr & error)15 worker_thread( boost::exception_ptr & error )
16     {
17     try
18         {
19         do_work();
20         error = boost::exception_ptr();
21         }
22     catch(
23     ... )
24         {
25         error = boost::current_exception();
26         }
27     }
28 
29 // ...continued
30 
31 void
work()32 work()
33     {
34     boost::exception_ptr error;
35     boost::thread t( boost::bind(worker_thread,boost::ref(error)) );
36     t.join();
37     if( error )
38         boost::rethrow_exception(error);
39     }
40