package javatest;
public class Test {
public static void aMethod()throws Exception{
try{
throw new Exception();
}
catch(Exception e){
System.out.println("exception000");
}
finally{
System.out.println("exception111");
}
}
public static void main(String args[]){
try{
aMethod();
}
catch(Exception e){
System.out.println("exception");
}
System.out.println("finished");
}
}
改程序执行结果为:
exception000
exception111
finished
若将黑体部分注释掉,则结果为
exception111
exception
finished
若将黑体和斜体部分都注释掉,则结果为
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "Finally" to complete BlockStatements
at javatest.Test.aMethod(Test.java:7)
at javatest.Test.main(Test.java:17)
会报错,编译不能通过。