Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2004-05-27 12:33:31


"Andreas Huber" <ah2003_at_[hidden]> wrote in message
news:loom.20040527T171933-644_at_post.gmane.org...
> [...]
> Why must a C++ destructor not fail (I guess I don't have to spell
> this out)?

Actually, it would have helped if you did. The reason d'tors must
not fail is that a fundamental guarantee of C++ is that d'tors are
always called on exit of the enclosing scope. Throwing d'tors
break this guarantee.

> Exactly the same reasons apply to exit actions!

Not quite. If there were a compelling reason that all exit actions
should be called upon leaving state, then the situations would be
analogous. But Dave is arguing that there is *not* such a
compelling reason. That's where the disagreement comes in.

> If C++ destructors could fail, that would make it impossible to
> correctly bail out of most error situations.

Yes, but that's not the first reason why we have non-throwing d'tors,
even though it *is* the reason why you want to have non-throwing
exit actions.

> Exactly the same argument applies to exit actions (even if you
> implement the exit action in a normal function).
> [...]

So in reality, your claim is that throwing exit actions would would
mask the original error, and thus make it difficult to impossible to
handle the original exception (and leaving your FSM in an invalid
state). But this is an artifact of your exception handling model, and
nothing intrinsic to exit actions. (It seems that you could have the
same problem with entry actions). I still think it's a good argument,
but the association with d'tors distracts from your main point.

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.691 / Virus Database: 452 - Release Date: 5/26/2004

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