SyntaxStudy
Sign Up
Python Exception Groups (Python 3.11+)
Python Advanced 5 min read

Exception Groups (Python 3.11+)

Exception Groups

Python 3.11 introduced ExceptionGroup and except* to handle multiple exceptions simultaneously — useful in async code.

Example
try:
    raise ExceptionGroup("errors", [
        ValueError("bad value"),
        TypeError("wrong type"),
    ])
except* ValueError as eg:
    print("Value errors:", eg.exceptions)
except* TypeError as eg:
    print("Type errors:", eg.exceptions)
Pro Tip

ExceptionGroup is designed for concurrent tasks that raise multiple errors.