Re: Exceptions

"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.



Relevant Pages

  • Contracted exceptions for Ada (was: Exceptions)
    ... The ARG has discussed "exception contracts" a couple of times, ... It is not optional it is "any exception may propagate." ... actual pool states themselves will never be checked at run-time (following ...
  • Re: contracted exceptions
    ... We discussed this subject in the ARG and no one had ... but it also would make any contracts not particularly relevant. ... violated exception contract caused Program_Error to be raised, the original, ... debugging harder. ...
  • Re: Contracted exceptions for Ada
    ... in my view exception contracts have to be static. ... The only way to statically enforce exception contracts is to use SPARK ... Ada. ...
  • Re: contracted exceptions
    ... in forcing them to ensure that callers' contracts are compatible. ... artificial work. ... With the throwing of an exception, in practice it is only exception clauses ... this is a fundamental disagreement on what is fault and what is error. ...
  • Re: Exceptions
    ... Yes if Constraint_Error shall not propagate further. ... Note that to argue against exception contracts on the basis that handling ... null handlers and the like.) ...