异常链抛出异常
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package yichang; public class TestYiChang { public static void main(String[] args) { // TODO Auto-generated method stub try { test_yichang3(); } catch (Exception e){ e.printStackTrace(); } } public static void test_yichang1() throws MyException{ throw new MyException(); } public static void test_yichang2() throws Exception{ try { test_yichang1(); } catch (Exception e) { throw new Exception( "异常2号" ,e); } } public static void test_yichang3() throws Exception{ try { test_yichang2(); } catch (Exception e) { throw new Exception( "异常3号" ,e); } } } |
问题描述:
1.还是不太理解trow new Exception的时候构造方法多传入一个异常对象e代表什么具体含义
2.主方法调用e.printstacktrack(), 此时e是test_yichang3抛出的异常对象,为什么可以打印前面test_yichang1和test_yichang2的异常堆栈信息
6
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧