Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-07-07 05:37:11


Emil Dotchevski wrote:

>Yes, but what happens if boost::wrap_string throws?
>
>I know you can work your way around this issue but it's going to be really
>hacky.
>
>
The C++ standard library contains a function that tests whether a stack
unwind is in progress. Only throw from the destructor if that function
returns false.
The function is broken in VC6 though. It always returns false.

I see different problems here. One is the hackish and completely
unintuitive way << works: it does not create a temporary (we can't have
more than one throw_ temp) and actually modifies its left argument. But
that's a style issue.
Far more important: doing this might wreak havoc with the compiler's
flow analysis. Consider:

int what_on_earth(earth &e)
{
  if(...) {
    return 1;
  }
  if(...) {
    return 2;
  }
  if(...) {
    return 3;
  }
  // Something bad happened, but it's a runtime possibility, so no
assert() but an exception.
  throw something_bad_happened();
}

Now change to throw_:

int what_on_earth(earth &e)
{
  // ...
  boost::throw_<something_bad_happened>() << e;
  // Does the compiler realize this is unreachable, or will it emit a
missing return value warning/error?
}

Sebastian Redl


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