A backport of PEP 654, providing exception groups and the 'except*' syntax for Python versions prior to 3.11. Current version: 1.3.1. Released on November 21, 2025. Maintained by The Trio Collective.
pip install exceptiongroupVerified import paths — ran on the pinned version, not inferred.
An example demonstrating the use of exception groups to handle multiple exceptions raised concurrently in Python 3.11 and later.
Use the 'exceptiongroup' package to backport exception groups and 'except*' syntax to earlier Python versions.
Import and use 'catch' from 'exceptiongroup' to handle exception groups appropriately.
Ensure that all required files and their parent directories are present and accessible at the expected paths during runtime. This may involve checking build processes, deployment configurations, or runtime environment variables that specify file locations.
pip install exceptiongroup
from exceptiongroup import ExceptionGroup, BaseExceptionGroup
For Python versions prior to 3.11, use the `exceptiongroup.catch()` context manager instead of `except*` syntax:
```python
from exceptiongroup import catch
with catch({ValueError: lambda eg: print(f"Caught ValueErrors: {eg.exceptions}")}):
raise ExceptionGroup("errors", [ValueError("bad value"), TypeError("bad type")])
```Separate your exception handling into different `try` blocks if you need to use both traditional `except` and `except*` (or the `exceptiongroup.catch()` equivalent), or refactor to use `except*` exclusively to handle individual exception types within an exception group.
```python
try:
# Code that might raise an ExceptionGroup
pass
except* ValueError:
print("Caught a ValueError subgroup")
try:
# Code that might raise a non-group exception
pass
except TypeError:
print("Caught a TypeError")
```