随意写一个类, 然后随意写二个方法
class Test{
public void printException1(){
throw new ArrayIndexOutOfBoundsException();
}
public void printException2(){
throw new ClassNotFoundException();
}}为什么编译器对printException2方法通不过, 报错"Unhandled exception type ClassNotFoundException"?
我尝试过像ArithmeticException(), ArrayStoreException() ,ClassCastException(), throw new IllegalArgumentException()等这些异常都可以像方法printException1这样写 都不会报错. 可像CloneNotSupportedException, EnumConstantNotPresentException, ClassNotFoundException, IOException就不可以为什么呢?
class Test{
public void printException1(){
throw new ArrayIndexOutOfBoundsException();
}
public void printException2(){
throw new ClassNotFoundException();
}}为什么编译器对printException2方法通不过, 报错"Unhandled exception type ClassNotFoundException"?
我尝试过像ArithmeticException(), ArrayStoreException() ,ClassCastException(), throw new IllegalArgumentException()等这些异常都可以像方法printException1这样写 都不会报错. 可像CloneNotSupportedException, EnumConstantNotPresentException, ClassNotFoundException, IOException就不可以为什么呢?
运行时异常不需要捕强制捉和声明抛出,而可查异常必须捕捉