Python UnicodeTranslateError Exception
Example
Raise a UnicodeTranslateError, and handle it:
try:
raise UnicodeTranslateError("abc", 0, 1, "example error")
except UnicodeTranslateError as e:
print("Error:", e.reason)
Try it Yourself »
Definition and Usage
The UnicodeTranslateError exception occurs when a character cannot be translated by a Unicode translation codec.
It is rarely seen, because the translate() method of strings does not raise it. The example raises it with raise, to show how it can be handled.
The four arguments are the text, the start and end positions of the problem, and the reason.
Related Pages
Read more about handling errors in our Python Try Except Tutorial.