动手动脑:finally语句块一定会被运行吗

运行

package demo;


public class Demo2 {

    
	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");
        
		}
    
	}


}

  

结果

in main
Exception is thrown in main

  

在catch中,结束程序,finally将不被执行

posted @ 2022-10-24 17:29  ashuai~  阅读(30)  评论(0)    收藏  举报