3 回答

TA貢獻(xiàn)317條經(jīng)驗(yàn) 獲得超240個(gè)贊
看異常應(yīng)該是你沒有定義DrunkExcpetion類,或者沒有引入
public?void?test1()throws?DrunkException?{ ?throw?new?DrunkException("喝車別開酒"); }
沒有必要即在方法中拋出異常又聲明這個(gè)方法會(huì)拋出異常,可以改成
public?void?test1()?{ ?throw?new?DrunkException("喝車別開酒"); }

TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超0個(gè)贊
public class Test2 {
public static void main(String[] args){
?Test2 tes = new Test2();
?try{
??tes.test2();
?}catch(Exception e){
??e.printStackTrace();
?}
?
}
public void test1()throws DrunkException {
?throw new DrunkException("喝車別開酒");
?
}
public void test2(){
?try{
?test1();
?}catch(Exception e){
??e.printStackTrace();
??RuntimeException? Exc = new RuntimeException("司機(jī)一滴酒,親人兩行淚");
??Exc.initCause(e);
??throw Exc;
??
?}
}
}
“public void test1()throws DrunkException {
?throw new DrunkException("喝車別開酒");
?
}”這一塊報(bào)錯(cuò)的
添加回答
舉報(bào)