<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## [使用 finally 進行清理](https://lingcoder.gitee.io/onjava8/#/book/15-Exceptions?id=%e4%bd%bf%e7%94%a8-finally-%e8%bf%9b%e8%a1%8c%e6%b8%85%e7%90%86) 有一些代碼片段,可能會希望無論 try 塊中的異常是否拋出,它們都能得到執行。這通常適用于內存回收之外的情況(因為回收由垃圾回收器完成),為了達到這個效果,可以在異常處理程序后面加上 finally 子句。完整的異常處理程序看起來像這樣: ~~~ try { // The guarded region: Dangerous activities // that might throw A, B, or C } catch(A a1) { // Handler for situation A } catch(B b1) { // Handler for situation B } catch(C c1) { // Handler for situation C } finally { // Activities that happen every time } ~~~ 為了證明 finally 子句總能運行,可以試試下面這個程序: ~~~ // exceptions/FinallyWorks.java // The finally clause is always executed class ThreeException extends Exception {} public class FinallyWorks { static int count = 0; public static void main(String[] args) { while(true) { try { // Post-increment is zero first time: if(count++ == 0) throw new ThreeException(); System.out.println("No exception"); } catch(ThreeException e) { System.out.println("ThreeException"); } finally { System.out.println("In finally clause"); if(count == 2) break; // out of "while" } } } } ~~~ 輸出為: ~~~ ThreeException In finally clause No exception In finally clause ~~~ 從輸出中發現,無論異常是否被拋出,finally 子句總能被執行。這也為解決 Java 不允許我們回到異常拋出點這一問題,提供了一個思路。如果將 try 塊放在循環里,就可以設置一種在程序執行前一定會遇到的異常狀況。還可以加入一個 static 類型的計數器或者別的裝置,使循環在結束以前能嘗試一定的次數。這將使程序的健壯性更上一個臺階。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看