public class Main {
static int test() {
int res = 0;
try {
int i = 10 / 0;
} catch (Exception e) {
res = 40;
return res;
} finally {
res = 100;
}
return 666;
}
static int test1() {
int res = 0;
try {
int i = 10 / 0;
return res;
} catch (Exception e) {
res = 40;
return res + 30;
} finally {
res = 100;
return res + 50;
}
}
static int test2() {
int res = 0;
try {
return res;
} finally {
return res + 50;
}
}
public static void main(String[] args) {
System.out.println(test()); //最终返回40;
System.out.println(test1()); //最终返回150;
System.out.println(test2()); //最终返回50;
}
}
try_catch_finally的坑
最新推荐文章于 2024-09-05 10:39:00 发布