Boost logo

Boost :

Subject: Re: [boost] [exception] boost::throw_exception vs deriving from boost::exception
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2012-10-07 15:53:50

On Sun, Oct 7, 2012 at 9:34 AM, Jeffrey Lee Hellrung, Jr.
<jeffrey.hellrung_at_[hidden]> wrote:
> On Sun, Oct 7, 2012 at 9:29 AM, John Salmon <john_at_[hidden]> wrote:
>> I'd like to use Boost.Exception's error_info capabilities in an existing
>> code
>> base. It seems to me that I have two choices:
>> 1 - find all the 'throw my_except(...)' in the code base and replace them
>> with boost::throw_exception(my_except(...)).
>> 2 - find all the struct my_except{...} definitions in the current code
>> base and replace them with:
>> struct my_except: virtual boost::exception {...}
>> I find #2 more appealing for the following practical reasons:

If your code base has a single exception type hierarchy, you can add
boost::exception as a base of its base type, like it is commonly done
with std::exception. That's more robust than specifying it as an added
virtual base of the individual exception types.

>> Are there reasons I should prefer boost::throw_exception instead?

In my own code I use a macro similar to BOOST_THROW_EXCEPTION to throw
exceptions. This lets me capture the throw location and store it in
the exception object, which helps track down unhandled exceptions.

>> can only think of one: boost::throw_exception also adds N2179 support
>> via enable_current_exception. This isn't a current concern, but our
>> compilers (gcc and clang) already support N2179 directly, so we can
>> use std::current_exception rather than boost::current_exception if the
>> need arises.
>> Are there other reasons to prefer boost::throw_exception?


Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at