Warning

Built-in ExceptionPython 2.0+Intermediate

Base class for warning categories

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching Warning
try:
    import warnings; warnings.warn("test warning")
except Warning as e:
    print(f"Caught Warning: {e}")
    print(f"Type: {type(e).__name__}")

Warning is raised when base class for warning categories. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore