PythonArithmeticError Exception
Example
AZeroDivisionError
occurs if you try to divide a number with 0.
AZeroDivisionError
is a type ofArithmeticError
.
print(10 / 0)
Try it Yourself »Definition and Usage
TheArithmeticError
exception is the base exception for the three arithmetic error excpetions:
FloatingPointError
OverflowError
ZeroDivisionError
You can handle theArithmeticError
in atry...except
statement, see the example below.
Exception Handling
Example
Handling theArithmeticError
in atry...except
statement:
try:
print(10 / 0)
except ArithmeticError:
print("Error in calculation")
except:
print("Something else went wrong")
Try it Yourself »print(10 / 0)
except ArithmeticError:
print("Error in calculation")
except:
print("Something else went wrong")