如何让PyCharm在运行时警告中打破?

Gar*_*ary 12 pycharm

我在代码中遇到了"运行时警告:在exp中遇到溢出...".如何在此警告中使pyCharm中断?它目前已超越它.

Gar*_*ary 15

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

numpy.seterr(all='raise')
Run Code Online (Sandbox Code Playgroud)

然后numpy将引发异常而不是RuntimeWarnings.然后可以通过PyCharm捕获异常.

  • 我认为你没有找到更好的解决方案来解决这个问题?因为断点会停止应用程序,因为我希望它可以让它中断但能够继续... (2认同)

小智 5

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

import warnings
warnings.simplefilter('error')
try:
   #code that generates warning
except:
   #put a breakpoint here
Run Code Online (Sandbox Code Playgroud)