Python 3.11+Exceptionsexception
BaseExceptionGroup
built-in exceptions
A group that may include system-exiting exceptions; parent of ExceptionGroup (3.11+).
Syntax
raise BaseExceptionGroup
The main trap: it derives from BaseException, not Exception, so a plain except Exception will not catch the group even when every exception inside it is an ordinary ValueError. The constructor is also sneaky — if all nested exceptions are Exception subclasses, BaseExceptionGroup(...) hands back an ExceptionGroup instead. To handle individual members use except*; a regular except clause matches the whole group at once.
Examples
try:
raise BaseExceptionGroup('группа', [KeyboardInterrupt()])
except BaseExceptionGroup as e:
print(type(e).__name__) # → BaseExceptionGroup
See also
Open in the full glossarydocs.python.orgReport an inaccuracy