3 ms·
It would crash but would print an error message along with a stack trace. The rust version will probably just crash with a confusing error.
by hasenj 9y ago
It would crash but would print an error message along with a stack trace. The rust version will probably just crash with a confusing error.
- wtetzner 9y agoWhy would the Rust version crash? The compiler will warn you if you if you haven't used a result type, and it's up to the programmer to decide what to do in the case of an error, just like when handling an exception. If you were going to use the JSON result for something, then you are forced to check if the result was Ok or Error. The only time you'd get a crash is if you just called .unwrap(), and even then you'll also get a stack trace.
- burntsushi 9y agoNote that you only get a stacktrace if you set the environment variable `RUST_BACKTRACE=1`. Otherwise, you get a standard panic message. The message from `unwrap` is probably unhelpful, which is why a lot of folks advocate using `expect`.
- hasenj 9y agoI think the point of the question was that in Python errors can still happen but they tend to get ignored when writing small scripts. So if one were to explicitly ignore errors in Rust how would the resulting program's behavior differ from the Python version?