checked exception: java中的Exception可以分为checked Exception和unchecked Exception。unchecked Exception包括RuntimeException,Error和他们的子类。对于unchecked Exception,在编程时不强制使用try{} catch{}或者throws来处理。例如NullPointerException。对于checked Exception,则在编程时必须用try{}catch{}来处理或者使用throws来抛出,否则在编译时会报错误。例如下面的代码: class Test{ public void waiting(){ this.wait(); } }在编译时会报错:D:\>javac Test.java Test.java:3: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown this.wait(); ^ 1 error
checked 在这里是形容词
不存在谁check谁
java中的Exception可以分为checked Exception和unchecked Exception。unchecked Exception包括RuntimeException,Error和他们的子类。对于unchecked Exception,在编程时不强制使用try{} catch{}或者throws来处理。例如NullPointerException。对于checked Exception,则在编程时必须用try{}catch{}来处理或者使用throws来抛出,否则在编译时会报错误。例如下面的代码:
class Test{
public void waiting(){
this.wait();
}
}在编译时会报错:D:\>javac Test.java
Test.java:3: unreported exception java.lang.InterruptedException; must be caught
or declared to be thrown
this.wait();
^
1 error