Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2008-04-20 15:07:23


Frank Mori Hess wrote:
> Here's a partial proof-of-concept implementation of exception_ptr for
> Linux, tested on gcc 4.1.2.
Have you tested this case:

void fn()
{
  exception_ptr p;
  try {
    throw runtime_error("hello, world");
  } catch(...) {
    p = current_exception();
  }
  rethrow_exception(p);
}

int main()
{
  try {
    fn();
  } catch(runtime_error &e) {
    std::cerr << e.what() << '\n';
  }
}

I believe your scheme will delete the exception object when p goes out
of scope, so either the exception mechanism itself will crash, or e will
be dangling.
Testing this out proves it. If I add some output statements, I get:

Rethrowing.
virtual test_exception::~test_exception()
Caught in main.

Even though it happens not to crash my simple scenario, it shows clearly
that the exception is destructed before it is caught in main.

This is still too simple, unfortunately. Replacing the cleanup function
is a good idea, but it's not enough to get around the limitations of
this method. I played around with it all day today.

I'm currently trying my next play: I need more data reachable from the
exception object, so I'm going to make it reachable. My plan is to let
the cleanup function pointer point to a structure whose first bytes
contain the code of a function that simply returns. In other words, I
hide more data behind the cleanup function. Wish me luck. :-)

Sebastian


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