Currently, the language provides no way to throw a checked excption without
either catching it or declaring it to be thrown in the current method.
(Notwithstanding a deprecated methon in Thread) The generics prototype
introduces a way to throw a checked exception with only a warning, which
is suppressed by default.
I believe this is a serious regression in the language. We should not
introduce such loopholes in type checking.
class Main {
static void hiddenThrow(Throwable t) {
class ExceptionHider<E extends Throwable> {
void hiddenThrow(Throwable e) throws E {
throw (E) e;
}
}
new ExceptionHider<RuntimeException>().hiddenThrow(t);
}
public static void main(String[] args) // no exception in method declaration
{
hiddenThrow(new java.io.IOException()); // throws IOException, hidden
}
}