public static void main(String[] args) {
try {
test();
}catch (Exception e) {
System.out.println("exception");
}
System.out.println("error");
}
public static void test() throws Error{
if(true) {
throw new AssertionError();
}
System.out.println("test");
}
}
首先在main方法中执行调用可能抛出Error异常的test()方法
执行test()方法,如果if语句判断条件成立,则会抛出AssertionError异常,不再执行后面语句
执行test()方法时有异常抛出,查看catch语句,查找对应的异常类型
main方法中catch语句的异常捕获类型为Expeciton,所以,test()方法中抛出的Error异常无法被捕获并处理,提示出现AssertionError异常,不再执行main方法中的其他语句