本文介绍了我可以从python中的finally块获取异常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本中有一个 try
/ finally
子句。可以从 finally
子句中获取确切的错误消息。
I have a try
/finally
clause in my script. Is it possible to get the exact error message from within the finally
clause?
推荐答案
不,在终于
时间 sys.exc_info
是全无,是否有异常
或不。使用:
No, at finally
time sys.exc_info
is all-None, whether there has been an exceptionor not. Use:
try:
whatever
except:
here sys.exc_info is valid
to re-raise the exception, use a bare `raise`
else:
here you know there was no exception
finally:
and here you can do exception-independent finalization
这篇关于我可以从python中的finally块获取异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!