<pre id="91lhj"></pre>

      <noframes id="91lhj"><noframes id="91lhj"><track id="91lhj"></track>
      <big id="91lhj"></big>

      <noframes id="91lhj"><pre id="91lhj"><strike id="91lhj"></strike></pre>
      <pre id="91lhj"><ruby id="91lhj"><ol id="91lhj"></ol></ruby></pre>

      在java 7中捕獲多個異常

      java 7使得我們能夠在同一個catch語句塊中捕獲多種不同的異常,這也叫做多重異常捕獲。

      在java7以前,我們可能要這樣做:

      01
      try{
      02

      03
      // execute code that may throw 1 of the 3 exceptions below.
      04

      05
      }catch(SQLException e) {
      06
      logger.log(e);
      07

      08
      }catch(IOException e) {
      09
      logger.log(e);
      10

      11
      }catch(Exception e) {
      12
      logger.severe(e);
      13
      }
      正如上面看到的,SQLException 和IOException 這兩個異常都是以相同的方式來處理的,但是你仍然要為這兩個異常寫兩個獨立的catch語句塊。

      java 7中你可以像下面這樣捕獲多個異常:

      01
      try{
      02

      03
      // execute code that may throw 1 of the 3 exceptions below.
      04

      05
      }catch(<strong>SQLException | IOException e</strong>) {
      06
      logger.log(e);
      07

      08
      }catch(Exception e) {
      09
      logger.severe(e);
      10
      }
      注意,第一個catch語句塊中的兩個異常名字是被管道字符|分割的。兩個異常類名之間的管道字符就是在同一個catch語句塊中聲明多個異常的方法。
      北大青鳥網上報名
      北大青鳥招生簡章
      免费无码AV片在线观看中文

      <pre id="91lhj"></pre>

          <noframes id="91lhj"><noframes id="91lhj"><track id="91lhj"></track>
          <big id="91lhj"></big>

          <noframes id="91lhj"><pre id="91lhj"><strike id="91lhj"></strike></pre>
          <pre id="91lhj"><ruby id="91lhj"><ol id="91lhj"></ol></ruby></pre>