Built-in Exceptions
UnicodeDecodeError — exception class
A byte sequence is invalid for the selected text decoder. The failed span indexes the input bytes, not Unicode characters. Check the source encoding and whether a streamed byte sequence is complete before choosing a replacement policy. Catch UnicodeDecodeError when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
UnicodeDecodeErrorReturn Value
type
The class object UnicodeDecodeError; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
try: bytes([255]).decode("utf-8")except UnicodeDecodeError as error: print(type(error).__name__)