From: Noah Stein (Noah_at_[hidden])
Date: 2002-10-31 09:40:19
> Martin Bosticky:
> I wanted to deal with exceptions. ie when exceptions are thrown,
> i wanted to
> execute code to test for invariants conditions. This is because exceptions
> could be cought later as part of normal programming flow but the object
> invariants could have been broken.
> The other reason is that if there is more than one "return" from
> the body of
> the function [run()] then this is always handled correctly. ie. next
> programmer after you managing the code can not awoid the postconditions
> checking easily by putting extra return somewhere in the middle
> of the body.
That seems like it will be pretty tough to handle both cases in C++. If
you're using the RAII idiom to handle post-conditions for multiple returns,
won't you end up checking your post-condition on an exception? Since you'll
violate that post-condition - by definition you haven't finished the
operation if you've thrown an assertion from it - you'll end up throwing out
a post-condition assertion exception instead of the original exception.
Unless of course there's some means to determine that your condition object
is being destroyed due to an exception. As far as I know, the language
won't help you there, you'd be forced to rely upon some solution you have to
manually create and keep updated properly. I'm not an exception expert, so
I could be wrong.
DBC is just an acronym to mean Design By Contract without having to type in
the whole phrase every time.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk