第一段代码
public class TestDemo12 {
static int f4() {
try {
throw new Exception("try error");
} catch (Exception e) {
throw new RuntimeException("catch error");
} finally {
System.out.print("f4");
}
}
public static void main(String[] args) {
try {
System.out.println(" :冒号1 " + f4());
} catch (Exception e) {
System.out.println(" :冒号2 " + e.getMessage());
}
}}
输出是f4 :冒号2 catch error
第二段代码
public class TestDemo13 {
static int f2() {
try {
throw new Exception("try error");
} catch (Exception e) {
return 2;
} finally {
System.out.print("f2");
}
}
public static void main(String[] args) {
try {
System.out.println(" :冒号1 " + f2());
} catch (Exception e) {
System.out.println(" :冒号2 ");
}
}}
输出是f2 :冒号1 2
try和catch里都有System.out.println,而且输出的内容都有冒号,请问冒号1和冒号2的输出顺序是怎么确定的?谢谢!