<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### [缺憾:異常丟失](https://lingcoder.gitee.io/onjava8/#/book/15-Exceptions?id=%e7%bc%ba%e6%86%be%ef%bc%9a%e5%bc%82%e5%b8%b8%e4%b8%a2%e5%a4%b1) 遺憾的是,Java 的異常實現也有瑕疵。異常作為程序出錯的標志,決不應該被忽略,但它還是有可能被輕易地忽略。用某些特殊的方式使用 finally 子句,就會發生這種情況: ~~~ // exceptions/LostMessage.java // How an exception can be lost class VeryImportantException extends Exception { @Override public String toString() { return "A very important exception!"; } } class HoHumException extends Exception { @Override public String toString() { return "A trivial exception"; } } public class LostMessage { void f() throws VeryImportantException { throw new VeryImportantException(); } void dispose() throws HoHumException { throw new HoHumException(); } public static void main(String[] args) { try { LostMessage lm = new LostMessage(); try { lm.f(); } finally { lm.dispose(); } } catch(VeryImportantException | HoHumException e) { System.out.println(e); } } } ~~~ 輸出為: ~~~ A trivial exception ~~~ 從輸出中可以看到,VeryImportantException 不見了,它被 finally 子句里的 HoHumException 所取代。這是相當嚴重的缺陷,因為異常可能會以一種比前面例子所示更微妙和難以察覺的方式完全丟失。相比之下,C++把“前一個異常還沒處理就拋出下一個異常”的情形看成是糟糕的編程錯誤。也許在 Java 的未來版本中會修正這個問題(另一方面,要把所有拋出異常的方法,如上例中的 dispose() 方法,全部打包放到 try-catch 子句里面)。 一種更加簡單的丟失異常的方式是從 finally 子句中返回: ~~~ // exceptions/ExceptionSilencer.java public class ExceptionSilencer { public static void main(String[] args) { try { throw new RuntimeException(); } finally { // Using 'return' inside the finally block // will silence any thrown exception. return; } } } ~~~ 如果運行這個程序,就會看到即使方法里拋出了異常,它也不會產生任何輸出。
                  <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>

                              哎呀哎呀视频在线观看