all Python 3Exceptionsexception
decimal.InvalidContext
module exceptions
A decimal context was configured with an invalid setting.
Syntax
raise decimal.InvalidContext
The decimal standard's condition for a broken context — an unknown rounding mode or a precision beyond what the implementation can handle. In CPython you will practically never see it: a context is validated on creation and assignment, so a bad rounding mode raises TypeError right away and an invalid prec or Emax raises ValueError, regardless of traps. If the condition ever does occur, it surfaces as InvalidOperation (trapped by default; untrapped, NaN), so a dedicated except InvalidContext is pointless.
Examples
import decimal
try:
raise decimal.InvalidContext
except decimal.InvalidContext as e:
print(type(e).__name__) # → InvalidContext
See also
Open in the full glossarydocs.python.orgReport an inaccuracy