What problem do exception groups and the `except*` syntax, introduced in Python 3.11, solve?
Answer
Before Python 3.11, code that ran multiple independent operations — such as several concurrent tasks — could only propagate a single exception at a time, forcing you to either stop at the first failure or manually collect errors into a list yourself. `ExceptionGroup` bundles multiple unrelated exceptions raised together into one object, and `except*` (star) syntax lets a handler match and process only the exceptions inside the group whose types it cares about, potentially handling different exception types from the same group in different `except*` clauses while the rest re-propagate.
Strong answer includes
- solves propagating multiple simultaneous unrelated exceptions at once
- ExceptionGroup bundles several exceptions into one raisable object
- except* matches and handles specific exception types within the group
Practical example
Running several validation checks that each might fail independently can raise one
ExceptionGroup("validation failed", [ValueError(...), TypeError(...)]), and
except* ValueError as eg:handles only the ValueError members.