python finally语句里面出现异常,python – break语句finally块中的swallows异常

https://docs.python.org/2.7/reference/compound_stmts.html#finally:

If finally is present, it specifies a ‘cleanup’ handler. The try clause is

executed, including any except and else clauses. If an exception occurs in

any of the clauses and is not handled, the exception is temporarily saved.

The finally clause is executed. If there is a saved exception, it is

re-raised at the end of the finally clause. If the finally clause raises

another exception or executes a return or break statement, the saved

exception is discarded

这也反映了从PEP341开始之前的最终声明:

这是一个尝试,除了finally块看起来像pre PEP341:

try:

try:

raiseMe()

except:

raise

finally:

#here is where cleanup is supposed to happen before raising error

break

#after finally code: raise error

由于错误的提升永远不会发生在finally块中,所以它从未实际上被提升。

为了保持与python版本2.4及更低版本的向后兼容性,必须以这种方式完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值