Skip to content

Implement chained exceptions #7069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 30, 2022
Merged

Implement chained exceptions #7069

merged 4 commits into from
Nov 30, 2022

Conversation

jepler
Copy link

@jepler jepler commented Oct 16, 2022

This should work substantially like Python. Two tests are added.

>>> try:
...     1/0
... except Exception as e:
...     raise RuntimeError("I am sad")
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
RuntimeError: I am sad 

TODO:

  • When the outer exception is raised implicitly (e.g., by computing 1/0) rather than by raise the context is not set

@jepler jepler force-pushed the exception-chain branch 3 times, most recently from 77572dc to 8077e5b Compare October 16, 2022 23:54
@jepler jepler marked this pull request as draft October 17, 2022 17:28
@jepler jepler force-pushed the exception-chain branch 2 times, most recently from 141df7d to 0523a77 Compare October 26, 2022 15:10
This adds the __cause__, __context__ and __suppress_context__
members to exception objects and makes e.g., `raise exc from cause`
set them in the same way as standard Python.
@jepler jepler marked this pull request as ready for review November 14, 2022 16:52
@tannewt tannewt requested a review from dhalbert November 15, 2022 23:09
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants