Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
Python interview question
Errors & context managersSeniorSpecialistTheory

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

Python example
ExceptionGroup("validation failed", [ValueError(...), TypeError(...)])

, and

Python example
except* ValueError as eg:

handles only the ValueError members.

#exceptions#python-3-11

Sources

Errors and ExceptionsPython Software Foundation · try/except/else/finally control flow and exception chainingWhat's new in Python 3.14Python Software Foundation · Current-version language and runtime changes, including template strings and free-threading support