先看两段代码,请试着分别写出它们的输出结果。
1、try-catch 块与 finally 块同时抛异常。
Java代码
import java.io.IOException;
public class ExceptionInFinallyBlock {
public static void main(String[] args) {
try {
try {
System.out.print("A");
throw new Exception("1");
} catch(Exception e) {
System.out.print("B");
throw new Exception("2");
} finally {
System.out.print("C");
throw new IOException("3");
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
2、try-catch 块与 finally 块同时包含 return 语句。
Java代码
public class ReturnStatementInFinallyBlockTest {
public static void main(String[] args) {