2 ms·
As far as not catching checked exceptions goes, this is actually possible in the Java language as well since the language allows throwing a generic type paramet
by peeters 12y ago
As far as not catching checked exceptions goes, this is actually possible in the Java language as well since the language allows throwing a generic type parameter. It's pretty difficult to do by accident though, and does at least give a compile warning.
public class Dangerous {
public static void main (String ... args) {
Dangerous.<RuntimeException>throwUnchecked(new IOException("Forgot to catch me!"));
}
static <T extends Exception> void throwUnchecked(Exception e) throws T{
throw (T) e;
}
}