all Python 3Exceptionsexception
decimal.Clamped
module exceptions
The exponent of a decimal result was changed to fit the allowed range.
Syntax
raise decimal.Clamped
Clamped is a signal, not an everyday error: its trap is off in the default context, so the computation goes on quietly and the only trace is a flag on the context. You have to enable the trap yourself to turn it into a real exception. The numeric value is not corrupted — only the exponent and the number of trailing zeros are adjusted to fit the representation limits, so this matters when you care about the exact scale of the result rather than its value.
Examples
import decimal
try:
raise decimal.Clamped
except decimal.Clamped as e:
print(type(e).__name__) # → Clamped
See also
Open in the full glossarydocs.python.orgReport an inaccuracy