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) {
RuntimeException newExc =
new RuntimeException(e);
//newExc.initCause(e);
throw newExc;
}
}
test1()函数抛出的是DrunkException异常,test2()函数调用了test1()并对test1()中的异常进行了处理,抛出的是RuntimeException异常,initCase(e)说明了test2()抛出的RuntimeException是由于DrunkException异常引起的。