思維有些混亂,能否用俗語(yǔ)解釋下這篇代碼
public class ChainTest {
public static void main(String[] args) {
ChainTest ct=new ChainTest();
try{
ct.test2();
}catch(Exception e){
e.printStackTrace();
}
}
public void test1() throws DrunkException{
throw new DrunkException("開(kāi)車別喝酒");
}
public void test2(){
try {
test1();
} catch (DrunkException e) {
// TODO Auto-generated catch block
RuntimeException newExc=new RuntimeException(e);
//newExc.initCause(e);
throw newExc;
}
}
}
2017-05-02
test1是拋出一個(gè)異常,test2是接收test1的異常并輸出運(yùn)行異常。
2017-05-02