在下面的代码中引发A第二个(B)时,我的第一个异常()会发生什么?
class A(Exception): pass
class B(Exception): pass
try:
try:
raise A('first')
finally:
raise B('second')
except X as c:
print(c)
Run Code Online (Sandbox Code Playgroud)
如果运行X = A我得到:
Traceback (most recent call last):
File "raising_more_exceptions.py", line 6, in
raise A('first')
__main__.A: first
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "raising_more_exceptions.py", line 8, in
raise B('second')
__main__.B: second
但如果X = B我得到:
second
这个问题专门针对Python 3,因为它的异常处理与Python 2完全不同.