Re: exceptions: checked or unchecked?
marlow.andrew@googlemail.com wrote:
Well, that's the theory but all too often to the practise is:
the exceptions are typically mis-handled by doing a catch and
report stack trace and then ignoring them. I have seen quite a lot of
this.
As Lew says, this is merely the programmer writing bad code. I've done
this before, but only when writing one-file quick, hacky programs (e.g.
the TSP Test program I wrote not long ago).
If you caught it at the wrong level then yes, otherwise no ;-)
Something I've learned from other languages. When writing in python,
what does |file.read| do if it can't find the file? I don't see the
answer in even the documentation. In another codebase I'm using, I have
to go to the documentation to find the answer, assuming that the writer
thought to put it into the documentation (which is generally not the
case). But in Java, the answer is told to you by the compiler: it throws
a FileNotFoundException. If I forgot that, I can now remember that I
have to handle this case.
Reading from a non-existent file is not an obvious case when perusing
code. If you don't catch, it will bubble up until you either get to a
catch-all handler. If this crosses application boundary layers, the
potential consequences are deadly.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth