Boost logo

Boost Users :

Subject: Re: [Boost-users] exception, filesystem, system_error and consistency
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-06-10 23:11:41


On Fri, Jun 10, 2011 at 1:09 PM, Michael Schuerig
<michael.lists_at_[hidden]> wrote:
> Poring over docs and headers, I noticed that neither
> boost::system::system_error nor boost::filesystem::filesystem_error are
> derived from boost::exception. Instead they implement an independent
> exception hierarchy.
>
> I found this disconcerting. For one thing, I have to catch and handle
> the respective exceptions separately. Far more importantly, though, I
> was expecting consistency among boost libraries and now see that this is
> not the case apparently.

The reason for this discrepancy is that Boost Exception was added
later than boost::filesystem and boost::system.

With the introduction of Boost Exception, we now have a single base
exception type for Boost libraries to use, but rather than modifying
all existing Boost libraries, the boost::throw_exception function
(which most Boost libraries have always been calling to throw
exceptions) was modified so that the object it throws is guaranteed to
derive from boost::exception. This is done at the point the
throw_exception template is instantiated: if you pass it an object of
type T which doesn't derive from boost::exception, it is wrapped in a
type that derives both from T and from boost::exception (this
mechanism is formally documented here:
http://www.boost.org/doc/libs/release/libs/exception/doc/throw_exception.html)

HTH,
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


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