Python Glossary Русский

all Python 3Exceptionsexception

decimal.DecimalException

module exceptions

The base class of all decimal signal exceptions (a subclass of ArithmeticError).

Syntax

raise decimal.DecimalException

It is the common ancestor of every decimal signal and at the same time a subclass of ArithmeticError, so except ArithmeticError catches it too — convenient, but too wide if plain divisions or overflows can happen nearby. The non-obvious part: most signals are not raised at all by default. The standard context traps only InvalidOperation, DivisionByZero and Overflow; the rest merely set a flag on the context, and that flag is the only way to notice them.

Examples

import decimal
try:
    raise decimal.DecimalException
except decimal.DecimalException as e:
    print(type(e).__name__)   # → DecimalException

See also

Open in the full glossarydocs.python.orgReport an inaccuracy