一、return 之后 finally 块也能执行
测试代码
public static void main(String[] args) {
// write your code here
try {
System.out.println("try...");
System.exit(1);
} finally {
System.out.println("finally...");
}
}
测试结果
try...
finally...
Process finished with exit code 0
二、exit() 方法执行后就不会执行 finally 块了
测试代码
public static void main(String[] args) {
// write your code here
try {
System.out.println("try...");
System.exit(1);
} finally {
System.out.println("finally...");
}
}
测试结果
try...
Process finished with exit code 1
网友评论