3 ms·
For Rust at least, I get a warning by default: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=869aae2aed2872770d91316e98efc682 https:/
by rectang 5y ago
For Rust at least, I get a warning by default:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=869aae2aed2872770d91316e98efc682 https://play.rust-lang.org/?version=stable&mode=debug&editio...
warning: unused `Result` that must be used
--> src/main.rs:7:5
|
7 | foo();
| ^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: this `Result` may be an `Err` variant, which should be handled
The quick fix is to change `foo();` to `foo().unwrap();`, which panics if the call returns an Err variant. But seeing `unwrap` in the code lets me know where an error may occur. That's better than the silent failure we get in many other languages when a result code is left unhandled or a potential exception isn't wrapped in a `try` block.
- randomdata 5y agoYes, like I said you can bake additional features into the language, but that is beyond the topic of the Result type. Go, with some modification, could allow the same type of mistake even without Result's existence.