3 ms·
Exception chaining (`raise from`) was new to me but after reading the docs it seems to be the default behavior in except/finally blocks, so the examples from th
by stevula 5y ago
Exception chaining (`raise from`) was new to me but after reading the docs it seems to be the default behavior in except/finally blocks, so the examples from the article don’t actually add anything. It doesn’t hurt to be explicit though.
https://docs.python.org/3/tutorial/errors.html#exception-chaining https://docs.python.org/3/tutorial/errors.html#exception-cha...
- Doxin 5y agoUsing "raise foo from bar" changes the message between the exceptions from "During handling of the above exception, another exception occurred:" to "The above exception was the direct cause of the following exception:" So yes, these days the whole "raise from" construct is nearly pointless. Used to be that exception chaining wasn't automatic though.
- aidos 5y agoI believe there’s a subtle difference in the meanings. You can raise or raise from. In either case the chaining means you get to see both messages. But one implies the original error is the cause. It’s so subtle that I don’t recall which is which!