1. 写出程序结果 :
class Demo {
public static void main(String[] args) {
try {
showExce();//异常 转到catch
System.out.println("A");
} catch (Exception e) {
System.out.println("B");
} finally {
//怎么都要执行
System.out.println("C");
}//try catch之外,直接运行
System.out.println("D");
}
public static void showExce() throws Exception {
throw new Exception();
}
}
运行结果: B C D
2. **写出程序结果 :
class Demo {
public static void func() {
try {
throw new Exception();//把下一行删除后 异常 进入func()方法里的catch输出B
System.out.println("A");//会报错 删除后正常编译运行
} catch (Exception e) {
System.out.println("B");
}
}
public static void main(String[] args) {
try {
func();//调用func方法 B 无异常
} catch (Exception e) {
System.out