Exception Attributes
UnicodeError.reason — exception attribute
Inspect the codec-provided explanation for a failure. Exact wording is codec- and version-dependent; use exception types and spans for program logic. A bare UnicodeError does not define this field.
Formal Syntax & Structure
python syntaxpython
error.reasonReturn Value
str
Metadata on the concrete Unicode exception, when applicable.
Working Example
Example Snippetpython
try: b"A\xffB".decode("utf-8")except UnicodeDecodeError as error: print(bool(error.reason))