all Python 3Exceptionsexception
Warning
built-in exceptions
Base class for all warning categories (usually shown, not raised).
Syntax
raise Warning
Warning inherits from Exception, so category=Warning in warnings.filterwarnings matches every warning category at once, and a broad except Exception will swallow a warning that a filter turned into an error. The class itself is rarely used directly: pick UserWarning for messages aimed at the caller and DeprecationWarning for obsolete API — the latter is hidden by default everywhere except code running as __main__.
Examples
try:
raise Warning
except Warning as e:
print(type(e).__name__) # → Warning
See also
Open in the full glossarydocs.python.orgReport an inaccuracy