首页 > 其他 > 详细

try...catch...finally执行顺序

时间:2017-05-16 10:30:58      阅读:315      评论:0      收藏:0      [点我收藏+]
 1 package test;
 2 
 3 public class TestDemo {
 4     
 5     public static String output = "";
 6     
 7     public static void main(String[] args) {
 8         foo(0);
 9         foo(1);
10         System.out.println(output);
11     }
12 
13     private static void foo(int i) {
14         try {
15             if(i == 1){
16                 throw new Exception();
17             }
18         } catch (Exception e) {
19             output += "2";
20             return;
21         } finally{
22             output += "3";
23         }
24         output += "4";
25         
26         
27     }
28 
29 }

输出的结果

3423

 

try...catch...finally执行顺序

原文:http://www.cnblogs.com/fzqm/p/6859934.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!