python - Python中的bare-except和broad-except有什么区别
问题描述
在 Python 中,我们可以编写两种异常处理逻辑
第一个是裸露的,除了:
try:
do_something()
except:
error_handling()
另一个是第一广泛的,除了:
try:
do_something()
except Exception:
error_handling()
它们之间的实际区别是什么?
解决方案
异常层次结构的顶部是 not Exception
, but BaseException
,它有四个子类:
Exception
GeneratorExit
SystemExit
KeyboardInterrupt
Abareexcept:
相当于except BaseException:
.
推荐阅读
- javascript - 将js函数应用于aspx表单上面板中的所有输入
- mysql - SQL 将多行合并为一列
- unit-testing - 当我改变初始化 Mockito 的方式时,Junit 测试被破坏
- xamarin.forms - 无法在 CollectionView 上选择两次相同的项目
- node.js - 如何使用聚合从 mongodb 中的两个集合中查询?
- java - Java:两个线程执行,直到布尔标志为假:第二个线程的第一次运行停止第一个线程
- php - 在 woocommerce 插件中用 PHP 创建 POST 的正确方法
- python - “语法错误:无法构建词法分析器” plyplus
- c# - 变量未在 void Start() 上赋值(菜鸟问题)
- swift - 如何在 Swift 中实现 CountedSet (NSCountedSet)?