异常链的小问题
为什么我public void test1() throws DrunkException{ 这里的DrunkException提示DrunkException cannot be resolved to a type呢...
Java入门第三季1-7异常链的
代码如下
package imoocChapterThree;
public class ChainTest {
/**
* test1():抛出异常
* test2():调用test1(),捕获异常,并且包装成运行时异常,继续抛出
* main方法中,调用test2(),尝试捕获test2()方法抛出的异常
* @param args
*/
public static void main(String[] args) {
ChainTest hello = new ChainTest();
try {
hello.test2();
} catch (Exception e) {
e.printStackTrace();
}
}
public void test1() throws DrunkException{
/*申明将要抛出这种抛出异常*/
throw new DrunkException("喝车别开酒!");
}
public void test2(){
try {
test1();
} catch (DrunkException e) {
// TODO: handle exception
RuntimeException newExc =
new RuntimeException("司机一滴酒,亲人两行泪");
newExc.initCause(e);
throw newExc;
}
}
}