Python FloatingPointError Exception
Example
Raise a FloatingPointError, and handle it:
try:
raise FloatingPointError("The calculation failed")
except FloatingPointError as e:
print("Error:", e)
Try it Yourself »
Definition and Usage
The FloatingPointError exception is meant for floating point calculations that fail.
Python does not raise it by default. A failing calculation with float numbers usually raises an OverflowError or a ZeroDivisionError instead, or gives a special value like inf.
Some libraries, like NumPy, can be set up to raise a FloatingPointError. The example raises it with raise, to show how it can be handled.
Related Pages
Read more about handling errors in our Python Try Except Tutorial.