大佬們,幫我看看為什么我的沒有運(yùn)行結(jié)果???
package com.imooc;
public class ChainTest {
? ? /**
? ? ?* test1():拋出了“喝大了”異常
? ? ?* test2():調(diào)用test1(),捕獲“喝大了”異常,并且包裝成運(yùn)行時(shí)異常,繼續(xù)拋出
? ? ?* main方法中,調(diào)用test2(),嘗試捕獲test2()拋出的異常
? ? ?* @param args
? ? ?*/
public static void main(String[] args) {
ChainTest ct = new ChainTest();
try {
ct.test2();
} catch (Exception e) {
// TODO: handle exception
}
}
public void test1() throws DrunkException{
throw new DrunkException("喝車別開酒!");
}
public void test2(){
try {
test1();
} catch (DrunkException e) {
// TODO Auto-generated catch block
RuntimeException newExc = new RuntimeException("司機(jī)一滴酒,親人兩行淚~~");
newExc.initCause(e);
throw newExc;
}
}
}
2018-02-01
main方法中的try 。。。 catch中的catch沒有結(jié)果,也就是你捕獲了異常但是你沒有處理結(jié)果,
2018-01-07
main方法中的catch下少了 e.printStackTrace();
2017-11-30
你的main()方法里catch中什么也沒寫 當(dāng)然什么也沒有。。。。