public class Test {
public static String output = "";
public static void foo(int i) {
try {
if (i == 1)
throw new Exception();
output += "1";
} catch (Exception e) {
output += "2";
return;
} finally {
output += "3";
}
output += "4";
}
public static void main(String[] args) {
foo(0);
System.out.println(output);
foo(1);
System.out.println(output);
}
}问输出结果是什么?
java异常中一个有趣的例子
最新推荐文章于 2024-11-28 11:29:55 发布
本文探讨了Java中使用try-catch-finally结构进行异常处理,并通过具体代码实例展示了如何在不同异常情况下的输出结果。
286

被折叠的 条评论
为什么被折叠?



