為什么編的是錯(cuò)誤的呢????
package demo.q;
public class ChainTest {
/*
?* test1()拋出"喝大了“異常
?* test2():調(diào)用test1()捕獲"喝大了"異常,并且包裝成運(yùn)行時(shí)異常,繼續(xù)拋出
?* main方法中,調(diào)用test2()嘗試捕獲test2()方法拋出的異常?
?*/
public static void main(String[] args) {
// TODO Auto-generated method stub
public void test1() throws DrunkException{
throw new? DrunkException("喝酒別開車!")
}
}
}
2019-07-21
你test1方法在主函數(shù)入口里面,肯定錯(cuò)誤的啊,寫法不對(duì)。解決方法,將test1()方法寫到主函數(shù)外部。