Boost logo

Boost :

Subject: Re: [boost] [exception] boost::throw_exception vs deriving from boost::exception
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-10-07 12:34:06

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:
> - there are fewer locations to change. Exceptions are defined less
> often and in fewer places than they are used.
> - there is less to remember. Developers who write new throw
> expressions need to remember nothing. Developers who define new
> exceptions must remember to derive them from boost::exception, but
> this is much less common.
> Are there reasons I should prefer boost::throw_exception instead? I
> 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?

I think it also allows you to disable exceptions (rather than throw, call a
user-defined exception handler and terminate). Other than that and
enable_current_exception, I don't think there's anything else that
throw_exception provides over throw.

- Jeff

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