Boost logo

Boost :

Subject: Re: [boost] Boost and exceptions
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-06-23 21:50:36

on Sat Jun 23 2012, "Robert Ramey" <> wrote:

> Dave Abrahams wrote:
>> on Sat Jun 23 2012, "Robert Ramey" <> wrote:
>>> If you really like boost::exception your code when you eventually can
>>> eventually rethrow
>>> catch (std::exception & e){ // not additon of &
>>> }
>> IIUC, even if you change it to catch by reference, as you should, and
>> even if std::exception weren't an abstract base class, which it is,
>> that approach will slice the caught exception and lose all the
>> information thrown with it. BOOST_EXCEPTION_THROW_EXCEPTION needs to
>> copy the exception object into this type it builds with multiple
>> inheritance from boost::exception, and it needs to do this with full
>> knowledge of the static type of the exception being thrown.
> wow I overlooked this.
> So in our case, if e was reference to an instance of a
> boost::archive::archive_exception object which holds all the
> interesting data, this information would be thrown away along with the
> actual type of the exception? That's terrible.

Like some other things we've discussed, that's essentially a C++
language feature. You couldn't do a plain "throw e" either, without
causing the slice. The only way to propagate the contents of e is
"throw;", which is obviously incapable of enhancing the thrown exception
in any way.

The the more you pick at Emil's design and the more I check your
arguments, the more impressed I am with the care he took. I may be
misunderstanding, but IIUC, the "problem" that he "fixed" was that his
change caused already-unsupported misuses of boost::throw_exception to
stop compiling. It's arguable that those misuses *should* be flagged
with compiler errors.

Dave Abrahams
BoostPro Computing

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