这个异常是如何工作的?
How does this exception work?
我想知道为什么 0
在执行这个函数时不打印:
def zeroDivision():
try:
try:
raise Exception("0")
finally:
result = 5/0
except Exception, e:
print e
我预计:
>>> zeroDivision()
0
integer division or modulo by zero
但我得到的是:
>>> zeroDivision()
integer division or modulo by zero
From the Python language reference:
If the finally
clause raises another exception [in this case, 5/0
] or executes a return or break statement, the saved exception [in this case, the Exception("0")
] is discarded
我想知道为什么 0
在执行这个函数时不打印:
def zeroDivision():
try:
try:
raise Exception("0")
finally:
result = 5/0
except Exception, e:
print e
我预计:
>>> zeroDivision()
0
integer division or modulo by zero
但我得到的是:
>>> zeroDivision()
integer division or modulo by zero
From the Python language reference:
If the
finally
clause raises another exception [in this case,5/0
] or executes a return or break statement, the saved exception [in this case, theException("0")
] is discarded