all Python 3Exceptionsexception
decimal.ConversionSyntax
module exceptions
An invalid string was given when creating a Decimal from a string.
Syntax
raise decimal.ConversionSyntax
Catching this class directly gets you nowhere: a malformed string makes decimal raise InvalidOperation, and ConversionSyntax is just the name of the underlying condition, not the object that reaches your except clause. Write except decimal.InvalidOperation instead. And if the InvalidOperation trap is disabled in the context, nothing is raised at all — you get a Decimal NaN back, and the failure has to be spotted via the context flags or an is_nan() check.
Examples
import decimal
try:
raise decimal.ConversionSyntax
except decimal.ConversionSyntax as e:
print(type(e).__name__) # → ConversionSyntax
See also
Open in the full glossarydocs.python.orgReport an inaccuracy