Boost logo

Boost :

Subject: [boost] [exception] boost::throw_exception vs deriving from boost::exception
From: John Salmon (john_at_[hidden])
Date: 2012-10-07 12:29:17

I'd like to use Boost.Exception's error_info capabilities in an existing
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?

John Salmon

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