Python Glossary Русский

all Python 3Exceptionsexception

UnicodeWarning

built-in exceptions

A Unicode-related warning.

Syntax

raise UnicodeWarning

This is a warning, not an error: by default the message is printed to stderr once and execution simply continues, so no except clause will ever see it. Turn it into a real exception with a filter — warnings.simplefilter('error', UnicodeWarning) or running with -W error. It descends directly from Warning rather than from UnicodeError, so except UnicodeError will not catch it.

Examples

try:
    raise UnicodeWarning
except UnicodeWarning as e:
    print(type(e).__name__)   # → UnicodeWarning

See also

Open in the full glossarydocs.python.orgReport an inaccuracy