zoukankan      html  css  js  c++  java
  • finally语句用法

    辨析:finally语句块一定会执行吗?

    请通过 SystemExitAndFinally.java示例程序回答上述问题

     public class SystemExitAndFinally {

       public static void main(String[] args)

        {

           try{   

                System.out.println("in main");   

                throw new Exception("Exception is thrown in main");        

                    //System.exit(0);       

               }

      catch(Exception e) 

                 {  

                     System.out.println(e.getMessage());

                     System.exit(0); 

                 }    

             finally

            {     

              System.out.println("in finally");

            }

       }

    }

    运行结果截图:

    这时候finally语句执行。

    //System.exit(0);  改为System.exit(0);  

    运行截图:

     

    求解答:finally语句什么时候执行?

  • 相关阅读:
    基于Spring的集群会话共享方案-spring session
    Tensorflow 模型线上部署
    Dijkstra算法
    BFS和DFS
    图的基本概念
    排序5
    排序4
    排序3
    排序2
    排序1
  • 原文地址:https://www.cnblogs.com/1995-qxl/p/4964328.html
Copyright © 2011-2022 走看看