new syntax for cleanup (was Re: destructors order not guaranteed?)

Bjorn Pettersen bjorn at roguewave.com
Mon Nov 6 20:17:16 CET 2000


Alex Martelli wrote:
[...]
> If a function called in a C++ destructor throws, and the
> exception exits from the destructor, what happens next is
> pandemonium.  "A destructor must not throw" is not written
> in the C++ standard, but it might as well have been, given
> the disasters caused by destructors that throw.  And having
> each destructor completely wrapped by a totally generic
> try/catch is hardly a solution -- exceptions are not meant
> to be totally ignored in such ways, and there's no telling
> how compromised the semantic state of your program might
> be if you do that in some library code.

I'm not sure I understand what you're saying here... There are two
situations that are possible here in C++:

 - an exception is thrown in a normal context (e.g. at the end of
   a scope). Such an exception will be caught by the nearest 
   enclosing handler.
 - an exception is thrown from a destructor during stack 
   unwinding (i.e. another exception happened). In this case
   std::terminate() is called.

Both cases are well defined and I would hardly call the results
"pandemonium"...?

-- bjorn




More information about the Python-list mailing list