控制臺無輸出
package test.exception;
public class ChainTest {
/*
* test1():拋出"喝大了"異常 test2():調(diào)用test1(),捕獲"喝大了"異常,并且包裝成 "運行時異常",繼續(xù)拋出
* main方法中,調(diào)用test2(),嘗試捕獲test2()方法拋出的異常
*/
public void test1() throws DrunkException {
new DrunkException("喝車別開酒!");
}
public void test2() {
try {
test1();
} catch (DrunkException e) {
// TODO Auto-generated catch block
RuntimeException newExc = new RuntimeException("司機一滴酒 親人兩行淚~~");
newExc.initCause(e);
throw newExc;
}
}
public static void main(String[] args) {
ChainTest ct = new ChainTest();
try {
ct.test2();
} catch (Exception e) {
e.printStackTrace();
}
}
}
2020-02-19
public void test1() throws DrunkException {
new DrunkException("喝車別開酒!");
}
少了 throw