BaseExceptionGroup
PythonERRORNotableException Handling

Group of BaseException instances (Python 3.11+)

Quick Answer

Use except* syntax (Python 3.11+) to handle individual exception types within a BaseExceptionGroup without catching unrelated errors.

Production Risk

Medium — unhandled BaseExceptionGroup will propagate all contained exceptions.

What this means

BaseExceptionGroup (Python 3.11+) wraps multiple BaseException instances — including KeyboardInterrupt and SystemExit — in a single exception. Use ExceptionGroup for Exception subclasses only; use BaseExceptionGroup when you need to group any BaseException.

Why it happens
  1. 1asyncio.gather / TaskGroup collecting multiple concurrent task failures including KeyboardInterrupt
  2. 2Libraries that wrap non-Exception base exceptions together

Fix

Use except* to handle grouped exceptions individually

Use except* to handle grouped exceptions individually
try:
    raise BaseExceptionGroup('signals', [
        KeyboardInterrupt(),
        SystemExit(1),
    ])
except* KeyboardInterrupt:
    print('interrupted')
except* SystemExit as eg:
    print('exit requested:', eg.exceptions)

Why this works

except* unwraps the group and routes each exception type to the matching handler, re-raising unmatched types.

Code examples
Difference from ExceptionGrouppython
# ExceptionGroup — only Exception subclasses
ExceptionGroup('errs', [ValueError('bad'), TypeError('wrong')])

# BaseExceptionGroup — any BaseException including KeyboardInterrupt
BaseExceptionGroup('mixed', [KeyboardInterrupt(), ValueError('bad')])
Same error in other languages
Version notes
Python 3.11

Both ExceptionGroup and BaseExceptionGroup were added in Python 3.11 via PEP 654.

Sources
Official documentation ↗

Python 3.11 — PEP 654

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Python errors