Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2008-04-15 13:19:42


Peter Dimov wrote:
> Note that N2179 doesn't require a copy to be made. If GCC allocates the
> exception objects on a heap - I have some recollections that it was doing
> that but I may be wrong - it might still be possible to implement
> current_exception to return a pointer to the active exception object... if
> there's a way to insert a reference count somewhere inside.
>

I took a larger stab at this, but I'm pretty much stumped right now. I
can't abuse the reference count in __cxa_exception, because if I do, the
handled exception stack won't be properly cleaned up.

I can use current_exception() to get the currently handled exception.
However, calling it again will yield a null pointer. That's because I
can't abuse handlerCount properly.

The exception_ptr works so far that it lets the exception escape the catch.

I can use rethrow_exception() to rethrow the exception. However, when I
catch it again, it won't escape the catch. I.e.

-------------
class foo {};

int main()
{
   exception_ptr p;
   try {
     throw foo();
   } catch(foo &) {
     p = current_exception();
     // Every subsequent current_exception() == 0
   }
   try {
     rethrow_exception(p);
   } catch(foo &) {
   } // Exception is destroyed here!
   // p dangles here!
}
--------------

And that's a simple scenario ...

Sebastian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk