cloning_2.cpp 910 B

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