{"id":316,"library":"exceptiongroup","title":"exceptiongroup","description":"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.","status":"active","version":"1.3.1","language":"python","source_language":"en","source_url":"https://github.com/python/exceptiongroup","tags":["exception handling","PEP 654","Python 3.11","backport","exception groups"],"install":[{"cmd":"pip install exceptiongroup","lang":"bash","label":"Install exceptiongroup"}],"dependencies":[{"reason":"Required for asynchronous operations","package":"trio","optional":false}],"imports":[{"note":"Correct import path for BaseExceptionGroup","symbol":"BaseExceptionGroup","correct":"from exceptiongroup import BaseExceptionGroup"},{"note":"Correct import path for ExceptionGroup","symbol":"ExceptionGroup","correct":"from exceptiongroup import ExceptionGroup"},{"note":"Correct import path for catch function","symbol":"catch","correct":"from exceptiongroup import catch"}],"quickstart":{"code":"import asyncio\nfrom exceptiongroup import BaseExceptionGroup, catch\n\nasync def read_file(filename):\n    with open(filename) as f:\n        data = f.read()\n    return data\n\nasync def main():\n    try:\n        async with asyncio.TaskGroup() as g:\n            g.create_task(read_file('unknown1.txt'))\n            g.create_task(read_file('unknown2.txt'))\n        print('All done')\n    except* FileNotFoundError as eg:\n        for e in eg.exceptions:\n            print(e)\n\nasyncio.run(main())","lang":"python","description":"An example demonstrating the use of exception groups to handle multiple exceptions raised concurrently in Python 3.11 and later."},"warnings":[{"fix":"Use the 'exceptiongroup' package to backport exception groups and 'except*' syntax to earlier Python versions.","message":"The 'except*' syntax introduced in PEP 654 is not available in Python versions prior to 3.11. Ensure compatibility with your Python version.","severity":"breaking","affected_versions":"<3.11"},{"fix":"Import and use 'catch' from 'exceptiongroup' to handle exception groups appropriately.","message":"The 'catch' function from 'exceptiongroup' is necessary to handle exception groups in Python versions prior to 3.11. Omitting it will result in unhandled exceptions.","severity":"gotcha","affected_versions":"<3.11"},{"fix":"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.","message":"The application failed to locate necessary files or directories, resulting in an '[Errno 2] No such file or directory' error. This indicates that critical files (e.g., 'unknown1.txt', 'unknown2.txt') expected by the application or its dependencies were not found.","severity":"breaking","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-12T13:01:05.620Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install exceptiongroup","cause":"The `exceptiongroup` library is a backport for Python versions prior to 3.11. If you are using Python 3.10 or older, you need to explicitly install the `exceptiongroup` package.","error":"ModuleNotFoundError: No module named 'exceptiongroup'"},{"fix":"from exceptiongroup import ExceptionGroup, BaseExceptionGroup","cause":"The `ExceptionGroup` and `BaseExceptionGroup` classes were introduced in Python 3.11. If you are using an older Python version and have installed the `exceptiongroup` backport, you must import them from the `exceptiongroup` package, not assume they are built-in.","error":"NameError: name 'ExceptionGroup' is not defined"},{"fix":"For Python versions prior to 3.11, use the `exceptiongroup.catch()` context manager instead of `except*` syntax:\n```python\nfrom exceptiongroup import catch\n\nwith catch({ValueError: lambda eg: print(f\"Caught ValueErrors: {eg.exceptions}\")}):\n    raise ExceptionGroup(\"errors\", [ValueError(\"bad value\"), TypeError(\"bad type\")])\n```","cause":"The `except*` syntax for handling exception groups is a new feature introduced in Python 3.11 (PEP 654). If you are using Python 3.10 or older, this syntax is not recognized by the interpreter, even if you have the `exceptiongroup` backport installed. The backport provides a `catch()` context manager for this functionality instead.","error":"SyntaxError: invalid syntax (when trying to use 'except*' on Python < 3.11)"},{"fix":"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.\n```python\ntry:\n    # Code that might raise an ExceptionGroup\n    pass\nexcept* ValueError:\n    print(\"Caught a ValueError subgroup\")\ntry:\n    # Code that might raise a non-group exception\n    pass\nexcept TypeError:\n    print(\"Caught a TypeError\")\n```","cause":"Python's exception handling syntax does not allow mixing traditional `except` clauses with the newer `except*` clauses within the same `try` block. This rule applies to Python 3.11+ where `except*` is native, and conceptually to the `exceptiongroup.catch()` backport which acts similarly.","error":"SyntaxError: cannot have both except and except* on the same try"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":60,"quickstart_tag":"reviewed","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2,"disk_size":"18.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":2,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.7,"disk_size":"20.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.7,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.6,"disk_size":"12.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.6,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":2,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.8,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.9,"disk_size":"17.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.9,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"reviewed","tag_description":"minor failures on some runtimes or slightly older test data","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}