直接通过简单的代码说明。
public class LostException {
public static void main(String[] args) {
try {
try {
throw new Exception("非常重要的异常!");
}finally {
throw new Exception("一个正常的异常");
}
} catch (Exception e){
e.printStackTrace();
}
}
}
运行结果:
Exception in thread "main" java.lang.Exception: 正常的异常
at com.exception.LostException.main(LostException.java:8)
从以上代码可以看出,“非常重要的异常”被忽略了。
在finally中抛出异常将导致之前的try语句内的异常被忽略。