首页 > 解决方案 > Python中的bare-except和broad-except有什么区别

问题描述

在 Python 中,我们可以编写两种异常处理逻辑

第一个是裸露的,除了:

try:
   do_something()
except:
   error_handling()

另一个是第一广泛的,除了:

try:
   do_something()
except Exception:
   error_handling()

它们之间的实际区别是什么?

标签: python

解决方案


异常层次结构的顶部是 not Exception, but BaseException,它有四个子类:

  • Exception
  • GeneratorExit
  • SystemExit
  • KeyboardInterrupt

Abareexcept:相当于except BaseException:.


推荐阅读