-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Closed
Description
Adding additional context to exceptions is possible in Python 3.11+, described in PEP 678 – Enriching Exceptions with Notes.
In vanilla REPL:
>>> try:
... 1/0
... except Exception as e:
... e.add_note("uh-oh")
... raise
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero
uh-oh
They don't show in the IPython REPL:
In [1]: try:
...: 1/0
...: except Exception as e:
...: e.add_note("uh-oh")
...: raise e
...:
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
Cell In[1], line 5
3 except Exception as e:
4 e.add_note("uh-oh")
----> 5 raise e
Cell In[1], line 2
1 try:
----> 2 1/0
3 except Exception as e:
4 e.add_note("uh-oh")
ZeroDivisionError: division by zero
In [2]: import sys
In [3]: sys.last_value.__notes__
Out[3]: ['uh-oh']
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels