class ScaryException extends Exception {}
class Exception1 extends Exception{}
public class TestExceptions{
public static void main(String[] args){
String test = "yes";
try{
System.out.println("start try");
doRisky(test);
System.out.println("end try");
}catch(Exception1 se1){
System.out.println("1 exception");
}catch(ScaryException se){
System.out.println("scary exception");
}finally{
System.out.println("finally");
}
System.out.println("end of main");
}
static void doRisky(String test) throws ScaryException,Exception1 {
System.out.println("start risky");
if("yes".equals(test)){
throw new Exception1();
}
if(true){
throw new ScaryException();}
System.out.println("end risky");
return;
}
}
调用的方法doRisky声明了两个检查异常,但是当调用方法doRisky之后发现第一个异常,doRisky抛出ScaryException异常对象,调用方catch解决异常,但是方法里还有一个检查异常没有抛出,问题是这时候已经跳转到catch(ScaryException se){}这里了,不会继续执行被调用的方法doRisky里后面的代码了,这要怎么解决?