UserWarning

Built-in ExceptionPython 2.0+Intermediate

Default category for warnings issued by the user

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

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

UserWarning is raised when default category for warnings issued by the user. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore