3 回答

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

TA貢獻1條經(jīng)驗 獲得超0個贊
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("司機一滴酒,親人兩行淚");
??Exc.initCause(e);
??throw Exc;
??
?}
}
}
“public void test1()throws DrunkException {
?throw new DrunkException("喝車別開酒");
?
}”這一塊報錯的
添加回答
舉報