I have encountered "RuntimeWarning: overflow encountered in exp ..." in my code. How do I make pyCharm break on this warning? It currently runs past it.
3 Answers
I did my own research and similarly to what @doctorlove said, do
numpy.seterr(all='raise')
then numpy will raise exceptions instead of RuntimeWarnings. The exceptions can then be caught by PyCharm.
3 Comments
You can use warning module to turn the warning into an error, then try-except and set break point:
import warnings
warnings.simplefilter('error')
try:
#code that generates warning
except:
#put a breakpoint here
2 Comments
A modification to Shuo Wang's answer:
import warnings
warnings.simplefilter('error')
try:
#code that generates warning
except:
#put a breakpoint here
pass
pass
Put the breakpoint on the pass statement that is inside the except clause. After you've reached that pass, step over it to land on the pass (which is optional, btw) that's outside the try-except block. This should allow you to see the call stack and all the variable values.