这里test没有抛出Exception对象,但我已经处理过了。由于Exception是一个经过检查的异常,因此它不会在catch块中抛出无法访问代码的编译器错误
class Ece extends Exception {}
public class Excep {
public static void test() { }
public static void main(String[] args) {
try {
test();
} catch (Exception E) {
}
}
}
类Exception
有RuntimeException
作为子类。 RuntimeException
及其子类不需要在methd签名中声明。
在这种情况下,您将捕获所有可能的Exception
子类,包括所有不需要签名声明的子类。如果您的test
方法抛出例如ArrayIndexOutOfBoundsException
,您将能够捕获并处理它,但test
签名将不会受到影响。
进一步阅读here