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.
Asked
Active
Viewed 8,659 times
23
-
1Are you using numpy? You could make it raise an exception instead and find out where. http://stackoverflow.com/questions/10519237/python-how-to-avoid-runtimewarning-in-function-definition or http://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html – doctorlove Jul 29 '13 at 22:22
2 Answers
30
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.

Gary
- 1,828
- 1
- 20
- 27
-
3I take it you didn't find a better solution to this problem? Because breakpoints stop the application, where as I would like to have it break but able to continue... – Shadow Dec 18 '13 at 06:10
-
@shadow The exception can be caught manually since you can localize it in your code using the debugger. – Kirill Bulygin Aug 01 '17 at 14:37
8
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
-
How do you remove it later? I want to catch warnings only in a specific block. I wish to add something like warnings.simplefilter('') after the except section – Shaq Feb 09 '23 at 14:32