Python Glossary Русский

all Python 3Exceptionsexception

decimal.Underflow

module exceptions

A decimal result is too small: it became subnormal and was rounded to zero.

Syntax

raise decimal.Underflow

Underflow inherits from Subnormal, Inexact and Rounded all at once, so a broad except decimal.Subnormal will swallow it too — put the more specific classes earlier in the except chain. Its trap is off by default, so without it the result simply collapses to a signed zero, and that silent zero is easy to misread as a bug in your own formula rather than a value pushed past Emin.

Examples

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

See also

Open in the full glossarydocs.python.orgReport an inaccuracy