Skip to content

Commit 8bcf118

Browse files
authored
gh-119786: move a few more details on exception handling from devguide to InternalDocs (#124989)
1 parent f474391 commit 8bcf118

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

InternalDocs/exception_handling.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ table. If it finds a handler, control flow transfers to it. Otherwise, the
7575
exception bubbles up to the caller, and the caller's frame is
7676
checked for a handler covering the `CALL` instruction. This
7777
repeats until a handler is found or the topmost frame is reached.
78-
If no handler is found, the program terminates. During unwinding,
78+
If no handler is found, then the interpreter function
79+
(``_PyEval_EvalFrameDefault()``) returns NULL. During unwinding,
7980
the traceback is constructed as each frame is added to it by
8081
``PyTraceBack_Here()``, which is in
8182
[Python/traceback.c](https://github.com/python/cpython/blob/main/Python/traceback.c).
@@ -182,3 +183,12 @@ The interpreter's function to lookup the table by instruction offset is
182183
The Python function ``_parse_exception_table()`` in
183184
[Lib/dis.py](https://github.com/python/cpython/blob/main/Lib/dis.py)
184185
returns the exception table content as a list of namedtuple instances.
186+
187+
Exception Chaining Implementation
188+
---------------------------------
189+
190+
[Exception chaining](https://docs.python.org/dev/tutorial/errors.html#exception-chaining)
191+
refers to setting the ``__context__`` and ``__cause__`` fields of an exception as it is
192+
being raised. The ``__context__`` field is set by ``_PyErr_SetObject()`` in
193+
:cpy-file:`Python/errors.c` (which is ultimately called by all ``PyErr_Set*()`` functions).
194+
The ``__cause__`` field (explicit chaining) is set by the ``RAISE_VARARGS`` bytecode.

0 commit comments

Comments
 (0)