Boost logo

Boost Users :

Subject: Re: [Boost-users] Exception: adding diagnostic information from a dtor?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-06-15 14:08:09


On Wed, Jun 15, 2011 at 1:08 AM, Michael Schuerig
<michael.lists_at_[hidden]> wrote:
> Is this a correct paraphrase: op<< either adds additional info to an
> exception or it raises another exception indicating its failure.

Yes. That way, if you get the original exception, it is guaranteed to
have the information needed to handle it; and in case op<< throws,
you'll get another (presumably more severe) exception.

> Let's see. When I catch one exception and while I add information to it,
> a new exception is thrown, it is this new exception that will propagate
> up the call stack. By contrast, when a destructor is called due to an
> exception and the code in the destructor does something that throws
> another exception, this causes program termination. -- Is that it?

I was assuming that program termination would be unacceptable, so the
destructor would have to catch and eat exceptions that op<< emits, and
this means that the catch site could be getting exceptions that are
missing random information, up to possibly not having any. So, it has
to be able to deal with any exception knowing *only* it's type.

Like I said, I'm not against this functionality being available, but
it isn't going to be trivial to implement. Essentially, when an
exception is created, a pointer allocated in thread-local storage
needs to be initialized to point to it so that destructors can access
it. However, you can have multiple active exceptions, so what is
really needed is a stack of pointers, allocated in thread-local
storage. And it has to be portable. :)

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