On Wed, Jul 16, 2008 at 4:38 PM,
Exceptions should be caught somewhere. The software engineer has to make certain of that by adding a try-catch-block on every interface boundary -- such boundaries are usually points where C++ borders on C or the operating system -- e.g. * the main-function, * window message handlers, * thread-functions, * callback handlers provided by certain frameworks e.g. to read from a file descriptor.
I don't think a thread package should provide features for storing exceptions, since this would require a new base class other than std::exception.
I assume your remark is regarding Boost Exception's ability to copy exceptions so that they can be re-thrown at a later time (this is independent of boost::thread.) This functionality is essentially identical to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html, except that without language support, for current_exception() to work, it is required that the original exception is thrown using boost::enable_current_exception(). There are no requirements that the exception type derives any particular base class. There is no problem to use enable_current_exception()/current_exception() with a type that derives from std::exception: struct foo: std::exception { }; //in a worker thread: ... throw boost::enable_error_info(foo()); //in the worker thread's main thread function: ... catch(...) { boost::exception_ptr ep=boost::current_exception(); //copy ep outside of the thread } //in the main thread, working with the exception_ptr returned from a worker thread: ... if( ep ) boost::rethrow_exception(ep); //throws foo
You may want to make certain that the exceptions thrown inside a thread function are not simply ignored -- e.g. the string returned from what() can be stored and displayed by the main thread.
It's even better to copy the entire exception object, not only the string returned from what(). Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode