Amen, brother!
I don't see the saving of six lines of typing to be worth the burial of this
serious a decision.
And tom, while the proposed @Safe (obviously it wouldn't be "@safe") "is" and
exception handler under the hood, it doesn't look like one. I espouse
writing explicit exception handlers for checked exceptions. The purpose of a
checked exception is to require explicit handling. To dodge that to save a
few lines of typing ("Ow! My poor fingers!") defeats that purpose,
This is not about typing, it's about reading.
This business about exception handlers being perfectly readable, and thus
a fine way of dealing with this situation, is nonsense. An exception
handler says to the reader "there is an exception which can occur here,
and this is how we deal with it". Here, we're talking about exceptions
which *cannot* occur. Writing catch blocks for them simply serves to give
the reader more to read, and once they've read it, confuses them as to why
it's there.
We evidently have different feelings about catch blocks, though. You
posted an example a few days ago, about closing streams, which had some
great number of catch blocks spread out down a page - taking a screen to
do what i'd do in a few lines. You think that's good code. I don't. I
thought that was shocking.
and as Arne points out, moves the realm of expected exception to
impossible error.
Have we been reading completely different threads? The whole point of this
is for situations where the exception *is* impossible. Or perhaps you
could explain to me how this line:
Reader r = new InputStreamReader(System.in, "UTF-8");
Is capable of throwing an IOException.
A checked exception is supposed to represent a recoverable situation, an
error an unrecoverable one. Why elevate the seriousness of the flaw?
You've missed the point - nothing is being elevated, because that catch
block *can never run*. And because it can never run, we put what is
effectively an assertion in it, so that if some day the impossible happens
(due to a bug in the standard library, or a rather surprising change in
the specification) and it does run, we find out about it.
Instead of calling lazy programming "Java as it is" and a call to
improve coding practices putting one's head in the sand, if you become a
proponent of making Java (not "java") coding rigorous and disciplined,
that's what looks like a reasonable idea. Why promote laziness, poor
design and whining?
Firstly, i think that Tomas's proposal is an outright good one - it would
make code clearer and more concise where used appropriately. That seems
like the most important test of a language feature to me.
Secondly, i think that where it could be misapplied, it would be better
than the misapplication of other features (empty catch blocks) that
currently happens. That also seems like a pretty good test.
I don't see how this could be construed as support for laziness, poor
design and whining.
tom