finally语句用法

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

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

 

 public class SystemExitAndFinally {blog

 

   public static void main(String[] args)get

 

    {it

 

       try{   io

 

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

 

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

 

                //System.exit(0);       im

 

           }static

 

  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语句何时执行?

相关文章
相关标签/搜索