我发现sys.excepthook的工作方式令人费解。 鉴于以下情况,我并没有找到一种方法,以防止异常被钩住。 总之,我从来没有达到印刷声明,但我相信理论上可以继续。 返回正确或错误也没有帮助吗?python中的sys.excepthook行为
import sys
from shutil import copy
from subprocess import Popen
def my_except_hook(etype, value, tb):
print("got an exception of type", etype)
if __name__ == '__main__':
sys.excepthook = my_except_hook
copy('sdflsdk')
print("here")
Popen('sdflkjdklsdj')
的输出是:
('got an exception of type', <type 'exceptions.TypeError'>)
为了获得更多的(信息)出你的所有的Python异常处理参见[Python的旅游#2:以异常(HTTP:// boodebr.org/main/python/tourist/taking-exception)文章。 – martineau 2012-07-06 16:35:02