class MyException extends Exception{
public MyException (String str){
super(str);
}
}
public class Test {
static public void shout(int i) throws MyException{
if(i==0) throw new MyException("first");
}
public static void main(String[] args) {
System.out.println("in main "+call());
}
public static int call() {
int i = 100;
try{
System.out.println("before try");
shout(0);
System.out.println("after try!");
return i*5;
}
catch(RuntimeException e){
e.printStackTrace();
i*=2;
return i*10;
}
finally{
i++;
System.out.println("finally block, i is : "+i);
return i*3;
}
}
}
上列代码中, 26 行的 shout(0)抛出的 MyException 没有被捕捉,按理来说应该编译不通过 但是能通过编译 但是如果我把 38 行的 return i*3;注释掉,就编译不过了 怎么回事?