public class Test001 {
public static void main(String[] args) {
try {
newex();
System.out.println('a');
}catch (Exception e){
System.out.print('b');
}finally {
System.out.print('c');
}
System.out.print('d');
}
public static void newex()throws Exception{
throw new Exception();
}
}
输出:bcd
finally块不管执行try块还是执行catch块,都会执行的
newex();抛出异常之后不会继续输出a,catch捕获异常,输出b,然后finally总是会执行,然后输出c,最后输出d。所以结果就是bcd