This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author iritkatriel
Recipients alonho, benjamin.peterson, chris.jerdonek, hniksic, iritkatriel, martin.panter, ncoghlan, nikratio, njs
Date 2021-12-11.15:36:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639237010.79.0.24342157039.issue18861@roundup.psfhosted.org>
In-reply-to
Content
I think this problem is actually simpler than what we've been discussing. 

First, note that by-and-large our current system works:

>>> try:
...   raise VE(1)
... except VE as e1:
...   try:
...     raise VE(2)
...   except VE as e2:
...     raise VE(3) from e2
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
ValueError: 2

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
ValueError: 3

----------------------------

Here VE(2) is the cause of VE(3) and VE(1) is the context of VE(2), so VE(1) is not hidden by the fact that VE(3) has a cause.

The reason that Nick's example didn't work is because he is doing

    raise VE(3) from VE(2)

i.e., creating a new exception VE(2) that doesn't have VE(1) as a context. I'm not sure there is a use case for this, so I don't think we need to worry about it.


The case of None does need fixing. We use None to indicate that there was no cause (while suppressing context). But None can't have a context, so VE(1) gets lost. We could, instead of None, use a NoException(Exception) class. This exception would be chained with the current exc_info() as context so that it works like VE(1) as above, and the traceback printing logic will know that it needs to be omitted from the output.


This proposal involves no changes to the exception propagation mechanism of the interpreter. It would require these changes:

1. Define the new exception type
2. in do_raise, in the case of raise-from the None case changes
3. traceback display code needs to be updated to omit NoExceptions
History
Date User Action Args
2021-12-11 15:36:50iritkatrielsetrecipients: + iritkatriel, ncoghlan, hniksic, benjamin.peterson, njs, nikratio, chris.jerdonek, alonho, martin.panter
2021-12-11 15:36:50iritkatrielsetmessageid: <1639237010.79.0.24342157039.issue18861@roundup.psfhosted.org>
2021-12-11 15:36:50iritkatriellinkissue18861 messages
2021-12-11 15:36:50iritkatrielcreate