假设以下代码。你知道吗
try:
some_code_1
except: # will it be called twice, if an error occures in finally?
some_code_2
finally:
some_code_3
假设在some_code_3
中发生异常。我是否需要在some_code_3
(见下文)周围使用一个额外的try-except子句,或者将再次调用some_code_2
的异常,这在原则上可能会导致无限循环?你知道吗
这是储蓄吗?你知道吗
try:
some_code_1
except: # will it be called twice, if an error occures in finally?
some_code_2
finally:
try:
some_code_3
except:
pass
示例代码中的finally不会捕获某些代码3的异常。你知道吗
是否需要从某些代码捕获异常取决于您的设计。你知道吗
试一试:
所以不,它不会以无限循环结束
python不会返回到执行流中,而是逐个语句返回。你知道吗
当它到达
finally
时,如果在那里抛出错误,它需要另一个句柄相关问题 更多 >
编程相关推荐