public class ExceptionTest {
public static void main(
String args[]) {
try {
ClassNotFoundException e=null;
}
catch (ClassNotFoundException e) { //compile error
//catch (Exception e) { //compile and run
System.out.println(e);
}
finally {
System.out.println("Finally");
}
}
}
For the above program, catch (Exception e) compile and run, but
catch (ClassNotFoundException e) has the following compile error:
Exception java.lang.ClassNotFoundException is never thrown in the body of the corresponding try statement.
I think java.lang.Exception is never thrown in the body of the corresponding try statement too, but why it doesn't create the compile error?
Thanks.