4 ms·
Wait...why is the OriginalException shown? The try catch already handled it, and the second exception doesn't "use" it and instead create a new one...it shouldn
by TrianguloY 2y ago
Wait...why is the OriginalException shown? The try catch already handled it, and the second exception doesn't "use" it and instead create a new one...it shouldn't be shown.
Is python automatically chaining the exceptions itself in a non-explicit manner?
Edit: found the PEP: https://peps.python.org/pep-3134/ https://peps.python.org/pep-3134/
- vanschelven 2y agoYes, the article doesn't mention this but indeed, in Python you can explicitly chain exceptions, which changes the message into "The above exception was the direct cause of the following exception:" You can also disable this behavior using the `from None` syntax. https://docs.python.org/3/tutorial/errors.html#exception-chaining https://docs.python.org/3/tutorial/errors.html#exception-cha...
- Sohcahtoa82 2y agoException chaining is a good thing. If your exception handler throws another exception, then knowing what caused the original exception is really good to know and greatly helps debugging, especially if your code is calling the handling code incorrectly. Without chaining, the root cause of the second exception would be hidden. If you find the chained exception output confusing, that's literally a skill issue. It's giving you invaluable information. Learn what it's telling you and you can fix bugs far more easily.