Python中的bare-except和broad-except有什么区别
在Python中,我们可以编写两种异常处理逻辑 第一个是裸露的,除了:Python中的bare-except和broad-except有什么区别,python,Python,在Python中,我们可以编写两种异常处理逻辑 第一个是裸露的,除了: try: do_something() except: error_handling() 另一个是第一个,除了: try: do_something() except Exception: error_handling() 它们之间的实际区别是什么?异常层次结构的顶部不是exception,而是BaseException,它有四个子类: 例外情况 GeneratorExit SystemExit
try:
do_something()
except:
error_handling()
另一个是第一个,除了:
try:
do_something()
except Exception:
error_handling()
它们之间的实际区别是什么?异常层次结构的顶部不是
exception
,而是BaseException
,它有四个子类:
例外情况
GeneratorExit
SystemExit
键盘中断
裸
except:
相当于except BaseException:
异常层次结构的顶部不是exception
,而是BaseException
,它有四个子类:
例外情况
GeneratorExit
SystemExit
键盘中断
裸
except:
相当于except:BaseException:
这是否回答了您的问题?这回答了你的问题吗?