小编uri*_*uri的帖子

在 PyCharm 下调试时不调用 sys.excepthook

我有自己的自定义 sys.excepthook 来处理错误(通过自定义错误消息),直接运行时它运行良好。由于将 PyCharm 更新到 2019.3 版本,此功能在调试时不起作用。用于在旧版本中工作。相反,PyCharm 只是打印堆栈并终止进程。

这是一个基本的代码。直接运行时有效,但调试时失败。

import sys
def myExceptHook(type, value, tb):
    print("there's been an error")

# reroute every exception through my hook
sys.excepthook = myExceptHook
raise Exception('error')
Run Code Online (Sandbox Code Playgroud)

调试时,我得到以下输出:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1434, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Projects/TubeEye/code/testraise.py", line 8, in <module>
    raise Exception('error')
Exception: error
Run Code Online (Sandbox Code Playgroud)

但是如果直接运行我得到(如预期的那样): …

python debugging pycharm

5
推荐指数
0
解决办法
249
查看次数

标签 统计

debugging ×1

pycharm ×1

python ×1