【发布时间】:2020-06-25 16:39:47
【问题描述】:
当我运行以下 java 代码时,我得到的输出是“ACDF”。有人可以解释一下如何处理最里面的 catch 块中抛出的运行时异常吗? (我希望它在将“E”附加到结果字符串变量的块中处理)
public class HelloWorld {
public static String someFunction() {
String result = "";
String str = null;
try {
try {
try {
result += "A";
str.length();
result += "B";
} catch (NullPointerException e) {
result += "C";
throw new RuntimeException(); // where this one goes????
} finally {
result += "D";
throw new Exception();
}
} catch (RuntimeException e) {
result += "E";
}
} catch (Exception e) {
result += "F";
}
return result;
}
public static void main(String[] args) {
System.out.println(someFunction());
}
}
【问题讨论】: