Re: exceptions: checked or unchecked?
marlow.andrew@googlemail.com wrote:
Joshua Cranmer wrote:
> I read somewhere that these
days people consider checked exceptions to be an
experiment that failed. Instead of people adding
the exceptions required to the throw list or handling
the exceptions internally 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.
Java is unique (AFAIK) in having checked exceptions. And Java is the
only language where I find exception handling workable. It makes writing
correct code easier and incorrect code harder: you already have the
exception, you might as well do something with it.
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.
....
"There does not now, nor will there ever, exist a programming language
in which it is the least bit hard to write bad programs."
[Flon, L. 1975. On research in structured programming. SIGPLAN Not. 10,
10 (Oct. 1975), 16-17. DOI= http://doi.acm.org/10.1145/987253.987256]
Sweeping errors under the carpet is a persistent and popular form of bad
programming.
I think the search for programming language features that make it hard
to write bad programs is futile. Rather, the objective should be to make
it as easy as possible to write good programs.
In that context, both checked and unchecked exceptions are useful. I use
checked exceptions for things that should normally be handled within the
program. Generally, the action should not just be to generate a stack
trace, but to somehow deal with the problem. If there is nothing better
to do, re-throw it wrapped in an unchecked exception. On the other hand,
unchecked exceptions are very useful for pervasive conditions that
should generally cause application failure.
Patricia