在使用java的捕获异常时出现return后的代码如何执行的,记录一下:
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
try {
System.out.println("suc");
return true;
} catch (Exception e) {
System.out.println("exception");
} finally {
System.out.println("finally");
}
return false;
}
//suc
//finally
//true
异常出现的时候:
public static void main(String[] args) {
System.out.println(test());
}
static boolean test() {
try {
if (3 / 0 == 1) {
System.out.println("error");
}
System.out.println("suc");
return true;
} catch (Exception e) {
System.out.println("exception");
} finally {
System.out.println("finally");
}
return false;
}
//exception
//finally
//false