Python OverflowError Exception
Example
If a mathematic function gets a too large number, it raises a OverflowError
:
import math
print(math.exp(999))
Try it Yourself »
Definition and Usage
The OverflowError
exception occurs when the result of a numeric calculation is too large.
The OverflowError
exception is one of three ArithmeticError
You can handle the OverflowError
in a try...except
statement, see the example below.
Exception Handling
Example
Handling the OverflowError
in a try...except
statement:
import math
try:
print(math.exp(999))
except OverflowError:
print("The number is too high")
except:
print("Something else went wrong")
Try it Yourself »