Boost logo

Boost Users :

Subject: Re: [Boost-users] Throwing an exception in a packaged_task: is there a clear example?
From: Emil Dotchevski (emil_at_[hidden])
Date: 2010-08-19 14:25:32


On Thu, Aug 19, 2010 at 8:54 AM, Mark Wilson <mwil_at_[hidden]> wrote:
> Hello,
>
> I am throwing an exception from a packaged_task, and then trying to catch it
> with f.get() (where f is a unique_future); it doesn't work, the program just
> terminates with:
>
> terminate called after throwing an instance of
> 'boost::exception_detail::clone_impl<boost::unknown_exception>'
>   what():  std::exception
>
>
> Is there a simple example somewhere, or could someone provide one, that
> makes clear how this mechanism is supposed to work?  The Threads
> documentation does not show how to do this...

Try replacing throw MyException with
BOOST_THROW_EXCEPTION(MyException()). You'll need to #include
<boost/throw_exception.hpp>.

The page at http://beta.boost.org/doc/libs/release/libs/exception/doc/current_exception.html
explains why you get a boost::unknown_exception.

HTH,
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net