19

我在我的代码中遇到了“RuntimeWarning:exp 中遇到溢出 ...”。如何让 pyCharm 打破这个警告?它目前运行通过它。

4

2 回答 2

24

我做了自己的研究,与@doctorlove 所说的类似,做

numpy.seterr(all='raise')

然后 numpy 将引发异常而不是 RuntimeWarnings。然后异常可以被 PyCharm 捕获。

于 2013-08-01T07:23:59.273 回答
5

您可以使用警告模块将警告转换为错误,然后尝试除并设置断点:

import warnings
warnings.simplefilter('error')
try:
   #code that generates warning
except:
   #put a breakpoint here
于 2020-11-05T21:47:02.363 回答