簡體   English   中英

Python中的bare-except和broad-except有什么區別

[英]What the difference between bare-except and broad-except in Python

在Python中,我們可以編寫兩種異常處理邏輯

第一個是裸露的,除了:

try:
   do_something()
except:
   error_handling()

另一個是第一廣泛的,除了:

try:
   do_something()
except Exception:
   error_handling()

它們之間的實際區別是什么?

異常層次結構的頂部不是Exception ,而是BaseException ,它有四個子類:

  • Exception
  • GeneratorExit
  • SystemExit
  • KeyboardInterrupt

一個裸的except:等價於except BaseException:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM