Skip to content

improve exception handling notes around lasti - #100467

Closed
P403n1x87 wants to merge 2 commits into
python:mainfrom
P403n1x87:chore/exception-table-lasti
Closed

improve exception handling notes around lasti#100467
P403n1x87 wants to merge 2 commits into
python:mainfrom
P403n1x87:chore/exception-table-lasti

Conversation

@P403n1x87

Copy link
Copy Markdown
Contributor

This change improves the description of the new exception table, focusing on describing the meaning of the lasti flag, and when one should expect it to be set.

@P403n1x87

Copy link
Copy Markdown
Contributor Author

@gvanrossum @markshannon following this discussion, I am proposing some improvements to the exception handling notes.

@merwok merwok changed the title chore: improve exception handling notes around lasti improve exception handling notes around lasti Dec 23, 2022
Comment thread Objects/exception_handling_notes.txt Outdated
This change improves the description of the new exception table,
focusing on describing the meaning of the lasti flag, and when one
should expect it to be set.
@P403n1x87
P403n1x87 force-pushed the chore/exception-table-lasti branch from 317b5bc to 2834cb9 Compare December 23, 2022 16:38
@P403n1x87
P403n1x87 requested a review from merwok December 23, 2022 16:39
Comment on lines +95 to +103
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.

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.

@encukou encukou added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 10, 2024
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

This document was moved to InternalDocs/exception_handling.md in #119815, which also added a "Reraising Exceptions and lasti" section describing this. Thank you anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review interpreter-core (Objects, Python, Grammar, and Parser dirs) skip issue skip news stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants