Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2001-04-19 08:20:59


> > Hmm, well that's still useful. For example, it makes file classes a
>> bit easier to write. Instead of using a close() method you can do the
>> close in the dtor. If an error is returned you can throw if
>> uncaught_exception() returns true. Too bad CodeWarrior doesn't
>> support it...
>
>Careful... you'd better be sure you didn't create your file object inside a
>catch block. I guess the chances are low, but all the same, it's a risk.
>
>Do you see now? If you use uncaught_exception to tell you whether it's
>"safe" to throw from a destructor, you have to either:
>1. Prohibit construction of the class inside catch blocks
>2. Limit your definition of "safe" to "won't cause immediate termination,
>but might skip unwinding actions and/or lose exception information".

I don't see the problem. We're in a catch block so the stack has
already been unwound. It's true that we may lose the original
exception, but if the file class is using exceptions that's going to
happen regardless of whether we throw in the dtor or a close() method.

   -- Jesse


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