public class FinallyTry {
public static void main(String[] args) throws Exception {
f();
}
public static String f() throws Exception{
try{
throw new Exception("异常1");
}catch (Exception e){
throw new Exception("异常2");
}finally {
return "1";
}
}
}
运行没有结果显示
public class FinallyTry {
public static void main(String[] args) throws Exception {
f();
}
public static String f() throws Exception{
try{
throw new Exception("异常1");
}catch (Exception e){
throw new Exception("异常2");
}finally {
try{
throw new Exception("异常3");
}catch (Exception e){
throw new Exception("异常4");
}
}
}
Exception in thread "main" java.lang.Exception: 异常4
at com.test.FinallyTry.f(FinallyTry.java:16)
at com.test.FinallyTry.main(FinallyTry.java:5)
--------在finally中抛异常或者return 会掩盖之前的异常