I have a function f
that is called several times in my code. The details of this function are not important, other than that it may at times generate a RuntimeWarning
because an iteration within the function is not making progress. When this happens I wish to print a message to the user alerting them which input resulted in the function raising the warning. Example:
for x in numpy.arange(5):
y = f(x)
#if calculation of y raised a RuntimeWarning then print "x = %.2f is problematic" % x
Any solutions?
EDIT:
I have seen the question that is referenced as the reason for this post being a duplicate, but I feel that my question is different. I simply want to print a message if a warning was generated for a particular function call... Not raise any exceptions.