`try / finally`中`return`如何杀死异常?

时间:2017-04-03 19:19:40

标签: python

我想知道为什么Python 3.3会因return语句中的try/finally而导致异常,请查看此代码:

import sys

def action1(): 
    try:
        action2() 
    finally: 
        return       # try/finally doesn't kill exceptions
                     # But with return, exceptions not propagated
def action2():
    raise Exception()

try:
    action1()

except Exception as e:   
    print("except clause")

这种行为是否可取,我们可以在哪里应用它?

0 个答案:

没有答案