try-catch-finally实例

1.示例代码

 1 package com.demo.advice;
 2 
 3 public class Test {
 4     public static String output = "";
 5 
 6     public static void foo(int i) {
 7         try {
 8             if (i == 1) {
 9                 throw new Exception();
10             }
11             output += "1";
12         } catch (Exception e) {
13             output += "2";
14             return;
15         } finally {
16             output += "3";
17         }
18         output += "4";
19     }
20 
21     public static void main(String args[]) {
22         foo(0);
23         foo(1);
24         System.out.println(output);
25     }
26 }

2.分解步骤

当 i ==0 时

当 i==1时 的分解步骤

猜你喜欢

转载自www.cnblogs.com/xaoco/p/9134540.html