将异常throw给上一层方法
@Test
public void test6() throws Exception{
try {
try {
try {
System.out.println("执行,,,,,,,");
int i = 1/0;
System.out.println("执行。。。。。。。");
} catch (Exception e) {
System.out.println("第三层,,,,,,,");
throw new RuntimeException(e);
}
} catch (Exception e) {
System.out.println("第二层,,,,,,,");
throw new RuntimeException(e);
}
} catch (Exception e) {
System.out.println("第一层,,,,,,,");
System.out.println(e.getMessage());
System.out.println("第一层。。。。。。。");
}
}
结果
执行,,,,,,,
第三层,,,,,,,
第二层,,,,,,,
第一层,,,,,,,
java.lang.RuntimeException: java.lang.ArithmeticException: / by zero
第一层。。。。。。。