Am I the only one who wanted to throw an Exception but couldn't because I was overriding
a method that threw nothing?
Happens all the time.
In particular, I'm subclassing Thread and can't throw an Exception in the run method. I suspect this is a more general issue though.
The usual answer is to throw some kind of RuntimeException,
with the original Exception as its "cause." For example,
void method() { // no "throws"
try {
somethingThatCanThrow();
} catch (IOException ex) {
throw new IllegalStateException(
"Fertilizer on fan", ex);
}
}
IllegalArgumentException and IllegalStateException are the
wrappers I find myself using most; there are plenty of others,
and of course you can implement your own RuntimeException subclass
if nothing seems suitable to the situation.
Some people, deeper thinkers than I, consider the whole
business of checked exceptions a nuisance or a misfeature. The
need for a dodge like the above can be seen as evidence for
that viewpoint, but I don't find it overwhelmingly convincing.
In any event, that's Java As It Is And Is Likely To Remain, so
we've got to get used to it whether we sneer at it or not.
Personally, I find it helpful that the compiler reminds me when
I've forgotten to deal with a checked exception; the inconvenience
of wrapping checked in unchecked exceptions seems a minor matter.