You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: internals/interpreter.rst
+1-21Lines changed: 1 addition & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -171,15 +171,7 @@ Do not confuse the evaluation stack with the call stack, which is used to implem
171
171
Error handling
172
172
==============
173
173
174
-
When an instruction like ``BINARY_OP`` encounters an error, an exception is raised.
175
-
At this point, a traceback entry is added to the exception (by ``PyTraceBack_Here()``) and cleanup is performed.
176
-
In the simplest case (absent any ``try`` blocks), this results in the remaining objects being popped off the evaluation stack and their reference count decremented (if not ``NULL``) .
177
-
Then the interpreter function (``_PyEval_EvalFrameDefault()``) returns ``NULL``.
178
-
179
-
However, if an exception is raised in a ``try`` block, the interpreter must jump to the corresponding ``except`` or ``finally`` block.
180
-
In 3.10 and before, there was a separate "block stack" which was used to keep track of nesting ``try`` blocks.
181
-
In 3.11, this mechanism has been replaced by a statically generated table, ``code->co_exceptiontable``,
182
-
which is described in detail in the `internals documentation
@@ -206,18 +198,6 @@ From C code, you have to call :c:func:`PyCode_Addr2Location`.
206
198
Fortunately, the locations table is only consulted by exception handling (to set ``tb_lineno``) and by tracing (to pass the line number to the tracing function).
207
199
In order to reduce the overhead during tracing, the mapping from instruction offset to line number is cached in the ``_co_linearray`` field.
208
200
209
-
Exception chaining
210
-
------------------
211
-
212
-
When an exception is raised during exception handling, the new exception is chained to the old one.
213
-
This is done by making the ``__context__`` field of the new exception point to the old one.
214
-
This is the responsibility of ``_PyErr_SetObject()`` in :cpy-file:`Python/errors.c` (which is ultimately called by all ``PyErr_Set*()`` functions).
215
-
Separately, if a statement of the form :samp:`raise {X} from {Y}` is executed, the ``__cause__`` field of the raised exception (:samp:`{X}`) is set to :samp:`{Y}`.
216
-
This is done by :c:func:`PyException_SetCause`, called in response to all ``RAISE_VARARGS`` instructions.
217
-
A special case is :samp:`raise {X} from None`, which sets the ``__cause__`` field to ``None`` (at the C level, it sets ``cause`` to ``NULL``).
0 commit comments