Built-in Exceptions
UnicodeError — exception class
Base for Unicode encoding, decoding and translation failures. Concrete codec exceptions expose the failed object, start and end indices and a reason. The base class alone need not have those attributes; catch the specific subclass for direction-dependent recovery. Catch UnicodeError when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
UnicodeErrorReturn Value
type
The class object UnicodeError; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
try: "é".encode("ascii")except UnicodeError as error: print(type(error).__name__)