Python Glossary Русский

all Python 3Exceptionsexception

OverflowError

built-in exceptions

The result of an arithmetic operation is too large for its type (typically float): math.exp(1000).

Syntax

raise OverflowError

Python integers are unbounded, so plain int arithmetic never overflows; this exception belongs to floats and to the C-level types underneath. Note the asymmetry: float arithmetic overflows silently to inf (1e308 * 10 raises nothing), while math functions and float() on a huge int do raise OverflowError. Wrap the specific computation, not the whole program.

Examples

try:
    raise OverflowError
except OverflowError as e:
    print(type(e).__name__)   # → OverflowError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy