Re: Contracted exceptions for Ada



Stefan Lucks <lucks@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> writes:

no need for a handler. Unfortunately, there's no Non_Zero subtype.

I am afraid, a non-zero subtype would move the problem around, rather
than solve it. The exception not raised by X/Y might then be raised
before, when you compute Y:=A-B.

On a second look, this might actually be useful better diagnostics. The
exception is raised closer to the point where the faulty value (the zero
Y) is created, rather than, perhaps, much later.

Exactly. Pushing the check to the caller makes it more likely that you
can prove it's true statically.

E.g. suppose you read a number from the keyboard, and pass it around,
store it in a data structure, retrieve it from the data structure, and
then divide by it. The "read" part should do input validation, or else
there's a bug. If all the subtypes of those parameters and data
structures had a "cannot equal zero" invariant, then the bug is isolated
to the "read" part. And if that part says "if Value /= 0 ..." then
it's easy to prove that the bug is not there.

- Bob
.



Relevant Pages

  • Re: Question about OO programming in Ada
    ... >>subtle memory leaks. ... (The usual problem cases are when an exception ... corrupt the ADT itself. ... corrupt the data structure, all the ADT designer has to do is wrap the ...
    (comp.lang.ada)
  • Re: Choosing not to throw exceptions like IllegalArguementException
    ... preventing debug from happening at all. ... like a recipe for converting easily debugged problems into subtle wrong ... Imagine the TreeCellRenderer wich throw an exception, and prevent the JTree from any repaint success, only because some bug happened before, which broke a specific assumption, and now there is the "impossible case" happening. ...
    (comp.lang.java.programmer)
  • Re: toward null-safe cookie cutter Comparators
    ... Sometimes I doubt that you have worked in a lot of brownfield ... because the customer would not complain as much. ... How does the customer *ever* see an exception? ... Reality is that I dislike to deliberately introduce a bug to my code, ...
    (comp.lang.java.programmer)
  • Re: How to pop the interpreters stack?
    ... because this isn't a bug. ... The fact that the exception is generated deep down some ... traceback are relevant and which aren't. ... lies in the input rather than some internal error in some subroutine you ...
    (comp.lang.python)
  • Re: Any Clojure users here?
    ... I've also fixed the minor bug in your code, to wit, it did Swing ... I actually prefer forcing programmers to add some kind of exception ... likely nil or a collection containing a nil where the ... And really, when you look deeply into it, the checked exceptions emperor ...
    (comp.lang.lisp)