Exception Methods

BaseExceptionGroup.split() — exception method

Partition a group into matching and nonmatching subgroups while preserving nested structure. Either side may be None. The original exceptions remain in the original group; filtering is not an in-place removal. Chaining, traceback and notes are carried into the derived groups.

Formal Syntax & Structure

python syntaxpython
group.split(condition, /)

Parameters & Attributes

NameTypeDescription
conditiontype | tuple[type, ...] | callableSelection rule applied to exceptions and groups.

Return Value

tuple[BaseExceptionGroup | None, BaseExceptionGroup | None]

Pair (match, rest).

Working Example

Example Snippetpython
group = ExceptionGroup("validation", [ValueError("quantity"), TypeError("price")])match, rest = group.split(ValueError)print(type(match.exceptions[0]).__name__)print(type(rest.exceptions[0]).__name__)print(len(group.exceptions))
Python Reference