|
Boost : |
From: Noah Stein (Noah_at_[hidden])
Date: 2002-10-28 05:11:11
> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]]On Behalf Of D language
> Sent: Monday, October 28, 2002 12:50 AM
> >Additionally, would you want to check your postconditions when
> >exceptions are thrown? I think there are situations both in favor and
> >against that.
> >
>
>
> No I would not want to do that. When exceptions are thrown, it is very
> likely the postconditions will fail because the program is out of its
> normall control flow. For that same reason, testing postconditions after
> exception is thrown does not make any sence. This makes me think that pre
> and post conditions in constructor/destructor of a class is not
> such a good
> idea afterall.
I would expect as you believe, too, that post conditions are likely to fail
when exceptions are thrown. A post condition of push_back() should be that
the size of the container is one more than when the function was entered.
As such, an out-of-memory exception will easily lead to a failure of
post-condition.
I do however think that invariants should be checked when exceptions are
thrown. After all, invariants should always be true.
>
> I am getting a feeling that there is no practical way of checking pre/post
> conditions with C++ other than the unfortunate self discipline.
I tend to agree. If C++ had a version of Java's final, pre/post conditions
could be heavily strengthened with the use parent concept classes. But
without final, derived classes can hide the member function that contains
the pre- and post-condition checking.
-- Noah
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk