try catch finally 有return的執行順序

try catch 中有return的時候,finally 的代碼一定會執行

測試代碼:

public class FinallyReturnDemo {

	
	 public static void main(String[] args) {
		 try{
			 System.out.println(1);
			 return ;
			
		 }catch(Exception e){
			 System.out.println(2);
		 }finally {
			 System.out.println(3);
		 }
		 System.out.println(4);
	}

}
運行代碼:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章