all Python 3Exceptionsexception
decimal.DivisionByZero
module exceptions
A non-zero Decimal was divided by zero (the decimal counterpart of ZeroDivisionError).
Syntax
raise decimal.DivisionByZero
The class inherits from both DecimalException and the built-in ZeroDivisionError, so an ordinary except ZeroDivisionError already covers Decimal division too; a separate branch is only worth it when you need to tell the two sources apart. Zero divided by zero does not land here — that is undefined and signals InvalidOperation instead. And with the trap disabled in the context nothing is raised: the operation simply yields a signed infinity.
Examples
import decimal
try:
raise decimal.DivisionByZero
except decimal.DivisionByZero as e:
print(type(e).__name__) # → DivisionByZero
See also
Open in the full glossarydocs.python.orgReport an inaccuracy