public static IOException method() {
try {
return new IOException();
} catch(FileNotFoundException e) {
return new FileNotFoundException();
}
}
This will not compile, because FileNotFoundException block will never be reached.
However, this will compile, although ClassCastException block will never be reached. Why this compiles and in first example not?
static void print() {
try {
throw new NullPointerException();
} catch(ClassCastException e) {
System.out.print("Class Cast ");
} finally {
System.out.print("Final ");
}
System.out.print("OCAJP ");
}