代码1:
代码2:
[img]/upload/attachment/51689/e04c6680-3799-3962-bc5d-728350b2fc1d.gif[/img]
代码2中在catch行会报错,说永远不会有IOException可以catch,为什么代码1却不会报错呢。
package scjp;
public class Demo464 {
public static void main(String args[]){
System.out.println("Before Try");
try {
} catch(NullPointerException t) {
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
代码2:
package scjp;
import java.io.IOException;
public class Demo464 {
public static void main(String args[]){
System.out.println("Before Try");
try {
} catch(IOException t) {
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
[img]/upload/attachment/51689/e04c6680-3799-3962-bc5d-728350b2fc1d.gif[/img]
代码2中在catch行会报错,说永远不会有IOException可以catch,为什么代码1却不会报错呢。