- From: "Randy Brukardt" <randy@xxxxxxxxxxxxxx>
- Date: Fri, 7 Dec 2007 21:30:05 -0600
"Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx> wrote in message
When "a way to force" reads "exceptions contract", then the answer is no,
there is no way, alas.
The ARG has discussed "exception contracts" a couple of times, but there
didn't seem that there was enough interest. The problem was mainly that they
simply don't look very valuable (for Ada, I'm not going to comment on other
languages) when the details are looked at, and they'd be fairly complex to
define. The biggest issue is compatibility, of course (since Ada has had
exceptions from the beginning, and never has had contracts, they'd have to
be optional - but it's not clear if optional contracts are worth much).
Another one is what to do if a contract is violated. The obvious answer of
raising Program_Error doesn't do anything other than lose information about
an exception, so that isn't very satisfying. (Static detection of contract
violations isn't possible in general because the contracts have to be
optional.) And then there is the problem of predefined exceptions like
Storage_Error -- every routine *can* raise Storage_Error, although few
*expect* to do so (if they don't allocate memory). Does that have to be
included in every contract? If so, that's ugly, and if not, the oddity of
not quite a contract is unpleasant. And there are more issues: the
maintenance cascade when an exception is added or removed; what about
call-back routines (think Process in the Containers library); and so on.
I'm sure that something could be worked out, but it seemed like there were
more valuable things to do.