日期:2014-05-20  浏览次数:20849 次

关于异常中的“check”?
EmptyStackException   is   a   not   a   checked   exception,   so   pop   is   not   required   to   state   that   it   might   occur.
  我一直不大清楚这个check是由那一部分来负责,是由编译器吗?那么又check哪些内容呢???

------解决方案--------------------
a checked exception
checked 在这里是形容词
不存在谁check谁
------解决方案--------------------
可能就是告诉你那个try{}里面的不需要catch这个Exception
------解决方案--------------------
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
------解决方案--------------------