经典指数          
原因
4457
浏览数
0
收藏数
 

下面代码的输出结果是什么?
public class ZeroTest {
    public static void main(String[] args) {
     try{
       int i = 100 / 0;
       System.out.print(i);
  }catch(Exception e){
       System.out.print(1);
       throw new RuntimeException();
  }finally{
       System.out.print(2);
  }
      System.out.print(3);
 }
 }
  • 3
  • 123
  • 1
  • 12

     举报   纠错  
 
切换
1 个答案

还是需要理解Try...catch...finally与直接throw的区别:try catch是直接处理,处理完成之后程序继续往下执行,throw则是将异常抛给它的上一级处理,程序便不往下执行了。本题的catch语句块里面,打印完1之后,又抛出了一个RuntimeException,程序并没有处理它,而是直接抛出,因此执行完finally语句块之后,程序终止了

 
切换
撰写答案