Handle several errors at once with ExceptionGroup and except*
Answer: Use ExceptionGroup when one operation needs to raise several unrelated errors together. Both ExceptionGroup and BaseExceptionGroup wrap the exceptions in the sequence excs. The msg parameter must be a string. Handle a group with except*, which matches their subgroups based on the types of the contained exceptions. ## The two classes
BaseExceptionGroup extends BaseException and can wrap any exception. ExceptionGroup extends Exception and can only wrap subclasses of Exception. That is why except Exception catches an ExceptionGroup but not BaseExceptionGroup. If every contained exception is an Exception instance, the BaseExceptionGroup constructor returns an ExceptionGroup instead, so the selection can be automatic. The ExceptionGroup constructor raises a TypeError if any contained exception is not an Exception subclass.
PEP 654 is the design document. In that text, when we refer to an exception group, we mean either an ExceptionGroup or a BaseExceptionGroup. A nested group is a tree of exceptions. The leaves are plain exceptions, and each internal node is a moment when the program grouped unrelated exceptions and raised them together. subgroup(condition) returns a group with the same metadata and nested structure, but only those exceptions for which the condition is true.
| ExceptionGroup | BaseExceptionGroup | |---|---| | ExceptionGroup | Wrap Exception subclasses | | BaseExceptionGroup | Wrap any BaseException subclass | | except* | Match subgroups by contained types | | except Exception | Catches an ExceptionGroup, not a BaseExceptionGroup | | subgroup | Same metadata, fewer nested exceptions |
See also
Claims
- id: C1 claim: except Exception catches ExceptionGroup but not BaseExceptionGroup. source: S1 evidence: "except Exception catches an ExceptionGroup but not BaseExceptionGroup"
- id: C3 claim: except matches subgroups by the types of the contained exceptions. source: S1 evidence: "except , which matches their subgroups based on the types"
- id: C4 claim: ExceptionGroup rejects nested exceptions that are not Exception instances. source: S2 evidence: "The ExceptionGroup constructor raises a TypeError"
Sources
- [S1] Built-in Exceptions. Python docs. https://docs.python.org/3/library/exceptions.html . License: PSF-2.0. Accessed 2026-11-19.
- [S2] PEP 654 – Exception Groups and except*. Python PEPs. https://peps.python.org/pep-0654/ . License: Public-Domain. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, Built-in Exceptions; Python PEPs, PEP 654 – Exception Groups and except*. PSF-2.0; Public-Domain. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs, Built-in Exceptions; Python PEPs, PEP 654 – Exception Groups and except*. PSF-2.0; Public-Domain.
Cite this
iinventedlight. 2026. "Handle several errors at once with ExceptionGroup and except*." iinventedlight Library, iil:note:9r3fz4c6, version of 2026-11-19. https://iinventedlight.com/library/notes/python-exception-groups/. License: CC-BY-4.0.
@misc{iil_note_9r3fz4c6,
author = {{iinventedlight}},
title = {{Handle several errors at once with ExceptionGroup and except*}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/python-exception-groups/},
note = {Permanent ID iil:note:9r3fz4c6. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-exception-groups.table.json (table; CC-BY-4.0)
- python-exception-groups.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-exception-groups.md.