Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Objects/exception_handling_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ If there is an entry, then:
3. push the exception to the stack.
4. jump to the target offset and resume execution.

Currently, the only opcode that requires the lasti flag to be set is RERAISE.
That is, if the jump described by an exception table points to an offset where
a RERAISE (with a non-zero oparg) occurs, the lasti is expected to be on the
stack, and therefore the lasti flag of the exception table entry must be set.
The last example gives an illustration of this. The first table entry describes
a jump where no RERAISE is executed. The second entry describes a jump where a
RERAISE with oparg 1 is executed. This means that the RERAISE will consume the
TOS and assume it is the lasti that was pushed when the exception occurred, as
instructed by the lasti flag.
Comment on lines +95 to +103

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's true that the lasti pushed on the stack is intended to be consumed by RESUME, this description lacks clarity on the Python constructs that generate RERAISE. It would be good to show some examples (maybe an exhaustive list) of constructs that do or don't use RERAISE. E.g.

try:
    xxx
except Exception:
    yyy

does not use RERAISE, but if we replace the last two lines with

finally:
    zzz

then we do. IIUC the other construct that uses RERAISE is the with statement, which after __exit__ returns may use RERAISE.

Maybe @iritkatriel or @markshannon can help review this.



Format of the exception table
-----------------------------
Expand Down