ExceptionGroup — Easy Examples
Groups multiple exceptions together (3.11+); used with except*
Triggering ExceptionGroup
How ExceptionGroup is raised and how to catch it.
python
# Triggering and catching ExceptionGroup try: raise ExceptionGroup("example error") except ExceptionGroup as e: print(f"Caught ExceptionGroup: {e}") print(f"Type: {type(e).__name__}")
ExceptionGroup is raised when groups multiple exceptions together (3.11+); used with except*. Always catch specific exceptions rather than bare except clauses.
Handling ExceptionGroup
Basic error handling pattern for ExceptionGroup.
python
# Safe handling pattern def safe_operation(): try: raise ExceptionGroup("example error") except ExceptionGroup: print("Operation failed gracefully") return None result = safe_operation() print(f"Result: {result}")
Wrapping risky operations in try/except blocks prevents your program from crashing.
Want to try these examples interactively?
Open Easy Playground