exceptiongroup

1.3.1 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

An example demonstrating the use of exception groups to handle multiple exceptions raised concurrently in Python 3.11 and later.

import asyncio
from exceptiongroup import BaseExceptionGroup, catch

async def read_file(filename):
    with open(filename) as f:
        data = f.read()
    return data

async def main():
    try:
        async with asyncio.TaskGroup() as g:
            g.create_task(read_file('unknown1.txt'))
            g.create_task(read_file('unknown2.txt'))
        print('All done')
    except* FileNotFoundError as eg:
        for e in eg.exceptions:
            print(e)

asyncio.run(main())

view raw JSON →