Exception

Built-in ExceptionPython 2.0+Beginner

Base class for all non-exit exceptions; used to define custom exceptions

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching Exception
try:
    raise Exception("generic exception")
except Exception as e:
    print(f"Caught Exception: {e}")
    print(f"Type: {type(e).__name__}")

Exception is raised when base class for all non-exit exceptions; used to define custom exceptions. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore