我们有内心的尝试,例如
try:
try: (problem here)
except: (goes here)
except: (will it go here) ??
Run Code Online (Sandbox Code Playgroud)
这是尝试除外的当前流程吗?如果外部try块内部被捕获异常,则是错误还是非错误?
不,除非第一个引发异常,否则它不会进入第二个.
当你进入该except条款时,你几乎都说"异常被捕获,我将处理它",除非你重新提出异常.例如,这个结构通常非常有用:
try:
some_code()
try:
some_more_code()
except Exception as exc:
fix_some_stuff()
raise exc
except Exception as exc:
fix_more_stuff()
Run Code Online (Sandbox Code Playgroud)
这允许您为同一个异常提供多个"修复"层.
| 归档时间: |
|
| 查看次数: |
609 次 |
| 最近记录: |