Built-in Exceptions
UnicodeWarning — exception class
Category for warnings concerning Unicode behavior. It is distinct from UnicodeError and its codec subclasses; warning filters decide whether it interrupts execution. The example explicitly promotes this warning category to an exception to make the result independent of default filters. Catch UnicodeWarning when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
UnicodeWarningReturn Value
type
The class object UnicodeWarning; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
import warningstry: with warnings.catch_warnings(): warnings.simplefilter("error", UnicodeWarning) warnings.warn("demo", UnicodeWarning)except UnicodeWarning as error: print(type(error).__name__)