Re: A matter of exception reporting style
James Kanze wrote:
Just a reminder as well---threading almost always involves C
interfaces at the lowest levels; you'll need to clone and
rethrow the exception if you want to propagate it over a join,
for example.
For the C code in between may not support exception
propagation.
In the case of join, it almost certainly doesn't, since
exception propagation involves stack unwinding, and you're
moving from one stack to another.
C++0x has a couple of answers here.
std::current_exception() returns a handle to the currently-handled
exception object; you can copy that handle however you like, and the
underlying exception object will continue to exist as long as there's an
outstanding handle. You can later use the handle to rethrow that
exception object. This is intended primarily for propagating exceptions
out of threads.
At a higher level, std::promise, std::unique_future, and
std::shared_future let you kick off a thread. Later you can query
whether it returned a result or threw an exception, and you can retreive
the result (which rethrows the exception if that's how the thread
terminated).
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)