思維有些混亂,能否用俗語解釋下這篇代碼
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("開車別喝酒");
}
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是拋出一個異常,test2是接收test1的異常并輸出運行異常。
2017-05-02