<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國際加速解決方案。 廣告
                # 異常的傳遞 ## 1\. try嵌套中 ~~~ import time try: f = open('test.txt') try: while True: content = f.readline() if len(content) == 0: break time.sleep(2) print(content) finally: f.close() print('關閉文件') except: print("沒有這個文件") ~~~ 運行結果: ~~~ In [26]: import time ...: try: ...: f = open('test.txt') ...: try: ...: while True: ...: content = f.readline() ...: if len(content) == 0: ...: break ...: time.sleep(2) ...: print(content) ...: finally: ...: f.close() ...: print('關閉文件') ...: except: ...: print("沒有這個文件") ...: finally: ...: print("最后的finally") ...: xxxxxxx--->這是test.txt文件中讀取到信息 ^C關閉文件 沒有這個文件 最后的finally ~~~ ## 2\. 函數嵌套調用中 ~~~ def test1(): print("----test1-1----") print(num) print("----test1-2----") def test2(): print("----test2-1----") test1() print("----test2-2----") def test3(): try: print("----test3-1----") test1() print("----test3-2----") except Exception as result: print("捕獲到了異常,信息是:%s"%result) print("----test3-2----") test3() print("------華麗的分割線-----") test2() ~~~ 運行結果: :-: ![](https://img.kancloud.cn/c1/6d/c16ddc2afe45849654942da3784d9fbe_834x398.png) 總結: * 如果try嵌套,那么如果里面的try沒有捕獲到這個異常,那么外面的try會接收到這個異常,然后進行處理,如果外邊的try依然沒有捕獲到,那么再進行傳遞。。。 * 如果一個異常是在一個函數中產生的,例如函數A---->函數B---->函數C,而異常是在函數C中產生的,那么如果函數C中沒有對這個異常進行處理,那么這個異常會傳遞到函數B中,如果函數B有異常處理那么就會按照函數B的處理方式進行執行;如果函數B也沒有異常處理,那么這個異常會繼續傳遞,以此類推。。。如果所有的函數都沒有處理,那么此時就會進行異常的默認處理,即通常見到的那樣 * 注意觀察上圖中,當調用test3函數時,在test1函數內部產生了異常,此異常被傳遞到test3函數中完成了異常處理,而當異常處理完后,并沒有返回到函數test1中進行執行,而是在函數test3中繼續執行
                  <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>

                              哎呀哎呀视频在线观看