package FindMistakes;
import org.omg.SendingContext.RunTime;
import java.io.IOException;
public class Tryexception {
public static void main(String[] args) throws Exception {
Tryexception x = new Tryexception();
x.method3();
}
void method1() throws IOException {
throw new IOException("13123");
}
int method2() throws IOException{
try {
method1();
}
catch (RuntimeException e) {
System.out.println("我抓住异常小怪兽了 嘻嘻");
System.out.println(e.getMessage());
return 0;//只有发生异常的时候才能有返回值所以会报错
}
finally{
System.out.println("最后");
return 0;//在这里就没问题了
}
}
void method3() throws RuntimeException{
try {
method2();
}
catch (Exception e) {
System.out.println("我抓住异常小怪兽2了 嘻嘻");
System.out.println(e.getMessage());
}
finally{
System.out.println("最后的最后");
}
}
}
最后
最后的最后