Objects/exceptions.c (part 8)
Source:
cpython 3.14 @ ab2d84fe1023/Objects/exceptions.c
This annotation covers ExceptionGroup (PEP 654). See objects_exceptions7_detail for BaseException.__new__, __traceback__, __cause__, and exception chaining.
Map
| Lines | Symbol | Role |
|---|---|---|
| 1-80 | BaseExceptionGroup.__new__ | Validate message + exceptions list |
| 81-160 | ExceptionGroup vs BaseExceptionGroup | Which type to use |
| 161-240 | BaseExceptionGroup.split | Partition into matching/non-matching groups |
| 241-360 | BaseExceptionGroup.subgroup | Filter to only matching exceptions |
| 361-500 | BaseExceptionGroup.derive | Create a new group with the same message |
Reading
BaseExceptionGroup.__new__
// CPython: Objects/exceptions.c:3280 BaseExceptionGroup_new
static PyObject *
BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *message, *excs;
PyArg_ParseTuple(args, "UO:BaseExceptionGroup", &message, &excs);
excs = PySequence_Tuple(excs); /* normalize to tuple */
/* Validate: each exception must be a BaseException */
for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(excs); i++) {
if (!PyExceptionInstance_Check(PyTuple_GET_ITEM(excs, i))) {
PyErr_Format(PyExc_TypeError,
"second argument ... must contain BaseExceptions");
return NULL;
}
}
...
}
ExceptionGroup("errors", [ValueError(1), TypeError(2)]) creates a group. The exceptions must be instances, not classes. The message is stored in args[0] (the standard BaseException.args convention).