@@ -68,18 +68,16 @@ Handling Exceptions
68
68
-------------------
69
69
70
70
At runtime, when an exception occurs, the interpreter calls
71
- `` get_exception_handler() `` in
72
- [ Python/ceval.c] ( https://github.com/python/cpython/blob/main/Python/ceval.c )
71
+ ` get_exception_handler() ` in [ Python/ceval.c] ( ../Python/ceval.c )
73
72
to look up the offset of the current instruction in the exception
74
73
table. If it finds a handler, control flow transfers to it. Otherwise, the
75
74
exception bubbles up to the caller, and the caller's frame is
76
75
checked for a handler covering the ` CALL ` instruction. This
77
76
repeats until a handler is found or the topmost frame is reached.
78
77
If no handler is found, then the interpreter function
79
- (`` _PyEval_EvalFrameDefault() ` ` ) returns NULL. During unwinding,
78
+ (` _PyEval_EvalFrameDefault() ` ) returns NULL. During unwinding,
80
79
the traceback is constructed as each frame is added to it by
81
- `` PyTraceBack_Here() `` , which is in
82
- [ Python/traceback.c] ( https://github.com/python/cpython/blob/main/Python/traceback.c ) .
80
+ ` PyTraceBack_Here() ` , which is in [ Python/traceback.c] ( ../Python/traceback.c ) .
83
81
84
82
Along with the location of an exception handler, each entry of the
85
83
exception table also contains the stack depth of the ` try ` instruction
@@ -174,22 +172,20 @@ which is then encoded as:
174
172
175
173
for a total of five bytes.
176
174
177
- The code to construct the exception table is in `` assemble_exception_table() ` `
178
- in [ Python/assemble.c] ( https://github.com/python/cpython/blob/main /Python/assemble.c) .
175
+ The code to construct the exception table is in ` assemble_exception_table() `
176
+ in [ Python/assemble.c] ( .. /Python/assemble.c) .
179
177
180
178
The interpreter's function to lookup the table by instruction offset is
181
- `` get_exception_handler() `` in
182
- [ Python/ceval.c] ( https://github.com/python/cpython/blob/main/Python/ceval.c ) .
183
- The Python function `` _parse_exception_table() `` in
184
- [ Lib/dis.py] ( https://github.com/python/cpython/blob/main/Lib/dis.py )
179
+ ` get_exception_handler() ` in [ Python/ceval.c] ( ../Python/ceval.c ) .
180
+ The Python function ` _parse_exception_table() ` in [ Lib/dis.py] ( ../Lib/dis.py )
185
181
returns the exception table content as a list of namedtuple instances.
186
182
187
183
Exception Chaining Implementation
188
184
---------------------------------
189
185
190
186
[ 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
- [ Python/errors.c] ( https://github.com/python/cpython/blob/main/ Python/errors.c)
194
- (which is ultimately called by all `` PyErr_Set*() `` functions).
195
- The `` __cause__ `` field (explicit chaining) is set by the `` RAISE_VARARGS ` ` bytecode.
187
+ refers to setting the ` __context__ ` and ` __cause__ ` fields of an exception as it is
188
+ being raised. The ` __context__ ` field is set by ` _PyErr_SetObject() ` in
189
+ [ Python/errors.c] ( ../ Python/errors.c) (which is ultimately called by all
190
+ ` PyErr_Set*() ` functions). The ` __cause__ ` field (explicit chaining) is set by
191
+ the ` RAISE_VARARGS ` bytecode.
0 commit comments