weibo_古德白嗨_0
2017-07-06 11:22
package com.imooc.six;
public class ChainTest {
/*
* test1():抛出“喝大了”异常
* test2():调用test1(),捕获“喝大了”异常,并且包装成运行时异常,继续抛出
* main方法中,调用test2(),尝试捕获test2()方法抛出的异常
*/
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("司机一滴酒,亲人两行泪");
//运行时异常(调用RuntimeException的含参构造器)
newExc.initCause(e);//对异常进行包装
throw newExc;
}
}
}
}在两个方法名的地方 void test1() 和test2()
eclipse都提示报错,不明白错误在哪里,求教~
你把这两个方法写在主方法里了,方法套方法能对吗,把这两个方法放到主方法外面类里边
Java入门第三季
409775 学习 · 4546 问题
相似问题