6. Use except* for exception groups

When handling independent failures from concurrent work, use except* with exception groups.

Exception groups require you to think in terms of independent failures rather than one monolithic error path. except* expresses that model directly and lets you handle different error types without flattening away the structure of the group.

Note

Python 3.11+

6.1. Don’t do this

1try:
2    run_parallel_jobs()
3except Exception as exc:
4    for error in exc.exceptions:
5        print(error)

6.2. Do this

1try:
2    run_parallel_jobs()
3except* ValueError as exc_group:
4    for error in exc_group.exceptions:
5        print(error)