[issue43002] Exception chaining accepts exception classes

Steven D'Aprano report at bugs.python.org
Sat Jan 23 07:05:10 EST 2021


Steven D'Aprano <steve+python at pearwood.info> added the comment:

How do you "the wrong message" to implicitly chain exceptions rather 
than explicitly?

The difference between:

     try:
         len(1)
     except TypeError as e:
         raise ValueError(msg) from e

and

     try:
         len(1)
     except TypeError as e:
       	 raise ValueError(msg)

is that the first traceback says:

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

and the second says:

"During handling of the above exception, another exception occurred"

Both messages are correct, but if the difference beween the two matters 
to you, feel free to use whichever form you prefer.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43002>
_______________________________________


More information about the Python-bugs-list mailing list