ezd*_*ena 5 python exception-handling exception try-except
谁能解释为什么下面的例子没有提高Exception?
def foo():
try:
0/0
except Exception:
print('in except')
raise
finally:
print('in finally')
return 'bar'
my_var = foo()
print(my_var)
Run Code Online (Sandbox Code Playgroud)
这只是返回:
in except
in finally
bar
Run Code Online (Sandbox Code Playgroud)
没有return 'bar'语句的相同代码抛出异常:
in except
in finally
Traceback (most recent call last):
File "test.py", line 10, in <module>
my_var = foo()
File "test.py", line 3, in foo
0/0
ZeroDivisionError: division by zero
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |