3 ms·
Am I the only one who finds Python's "forwards" backtraces confusing compared to every other language I've used? I can't help but think at least part of this co
by o11c 2y ago
Am I the only one who finds Python's "forwards" backtraces confusing compared to every other language I've used? I can't help but think at least part of this confusion is because of that.
That said:
* Would printing the trace as a tree actually clarify anything?
* Good code almost always minimizes the amount of code in an exception handler.
* `raise_exception()` is generally bad practice; consider `raise get_exception()` if you need something complicated (among others, this allows choice of `from`)
* `raise ... from None` is useful since it's often the most recent stacktrace that's actually relevant.
* `raise ... from e` likely implies that it is the older stacktrace that's most relevant; ideally this would just be a single annotation on a particular frame "exception was replaced here".
- silenced_trope 2y agoyes - I'm currently at a new job where I work on a python back-end, but there's also java/kotlin microservices, and I do front-end web with typescript or mobile with java/kotlin python is the only one doing this weird crap
- vanschelven 2y agoYou're probably not the only one, but as a Python developer of 20 years I can assure you that the confusion _for me_ is not caused by the order of the Stacktrace itself, but specifically by the way chained exceptions are shown. `raise_exception()` in the example is just to ensure a trivial example which still has a stacktrace in the handler (this is not uncommon in reality, though in reality the called function is not typically called with the goal of triggering yet another example)
- EdwardDiego 2y agoTIL `raise from` especially the `raise from None`, yeesh
- Sohcahtoa82 2y ago> * Would printing the trace as a tree actually clarify anything? Could you give an example of what this tree would look like? A stack is entirely linear. I've never had a problem with Python's stack traces. Certainly better than Java, where the paradigms rely on a ridiculous amount of introspection, reflection, and abstraction, so your stack traces end up being a hundred lines long, with half of them being ".invoke()".