Re:Where Everything Went Wrong: Error Handling and Error Mes...
by ymbeld on Friday February 19, 2021 @12:38PM
(#26195606)
I don’t get why this is off by default for debug builds though. Maybe that’s a separate concern.
Re:Where Everything Went Wrong: Error Handling and Error Mes...
by alpaca128 on Friday February 19, 2021 @01:08PM
(#26195980)
In my experience enabling the backtrace is necessary in very few cases. I've defined a bash alias to save me a little typing in those situations. As it can be turned on persistently by setting a single environment variable I'd say it's a good middle ground.
Re:Where Everything Went Wrong: Error Handling and Error Mes...
by barrkel on Friday February 19, 2021 @01:09PM
(#26195992)
In other compiled languages, stack traces can be supported by looking up code references on the stack in a map of executable addresses to source code locations.
Even in the absence of stack frames, the mere contents of the stack with lookups where possible is really useful, and usually more than enough.
The cost is a little code to do lookups at runtime, and making the mapping data available (typically compressed and embedded in the executable).
(Note that this isn't stack unwinding or exceptions. This is backtraces. Rust, like most languages which embed errors in return values, makes the developer do the stack unwinding manually.)
I think you're misunderstanding what the OP is trying to show here. If all you want is a backtrace, then Rust supports that out of the box. Here's an approximation of the full error message that you would see from the first example in the post:
The OP has omitted the next line, which tells you how to receive a backtrace. Backtraces are off by default in Rust because, unlike Java, Rust has a lightweight, C-style runtime that tries not to impose any runtime cost that the programmer did not ask for.