Boost logo

Boost Users :

Subject: Re: [Boost-users] [exception] Using Boost.Exception infrastructure without using boost::exception
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2011-05-29 01:21:30


On Sat, 28 May 2011 21:57:34 -0700, Emil Dotchevski
<emildotchevski_at_[hidden]> wrote:

> On Sat, May 28, 2011 at 9:50 PM, Mostafa
> <mostafa_working_away_at_[hidden]> wrote:
>> On Sat, 28 May 2011 21:01:56 -0700, Emil Dotchevski
>> <emildotchevski_at_[hidden]> wrote:
>>
>>> On Sat, May 28, 2011 at 8:37 PM, Mostafa
>>> <mostafa_working_away_at_[hidden]>
>>> wrote:
>>>>>
>>>>> All of the Boost Exception functionality works only if the exceptions
>>>>> derive from boost::exception. Your only two choices are to do it
>>>>> explicitly or to call boost::throw_exception which does it for you.
>>>>
>>>> It seems that some functionality doesn't, namely
>>>> boost::enable_current_exception, and I was hoping to leverage such
>>>> functionality to achieve my aforementioned goal.
>>>
>>> boost::enable_current_exception enables the
>>> boost::current_exception/boost::exception_ptr support by returning an
>>> object that derives from boost::exception *and* the type of the passed
>>> object.
>>>
>>> Therefore:
>>>
>>> throw boost::enable_current_exception(my_exception());
>>>
>>> satisfies the requirement for deriving from boost::exception without
>>> requiring my_exception to derive from boost::exception.
>>
>> If that is so, then that fact is omitted from the documentation for
>> boost::enable_current_exception, please see:
>
> Ah right, my mistake! It returns a type that derives from an
> unspecified type and T. The documentation is correct.

I do try to do my homework before posting here. :)

Now, back to the original purpose of my postings:

My Requirements:
----------------
To use Boost.Exception tools to make my exceptions transportable between
threads without explicitly or implicitly deriving from Boost.Exception.

So it seems I'm halfway there with "throw
boost::enable_current_exception(my_exception());". Now I would like to
rethrow from some catch site, it is my understanding then that I would
need to use boost::rethrow_exception() (in order to stay within the
parameters of my requirements). But boost::rethrow_exception requires a
boost::exception_ptr reference (which seems can only be gotten via
boost::current_exception). Now, does using "throw
boost::enable_current_exception(my_exception());" with class my_exception
which does not derive from boost::exception support the exception_ptr
functionality that is need for boost::rethrow_exception?

Thanks,

Mostafa


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