I also sometimes include log statements in specific error branches for debugging and delete them afterwards. That's trivially possible in the Go version but requires more effort in the shorter variants (e.g. also if the funcitons throw exceptions instead of returning errors in other languages).
Because you would rather pay the ongoing cost of writing (and worse, having to read) thousands of pointless `if err != nil` blocks than take three minutes to see exactly what try! does, which is (almost) exactly the Rust equivalent of just that.
> That's trivially possible in the Go version
It's also trivially possible in the Rust version, except you don't pay a ludicrous cost in readability of the logic flow in the thousands of other places you have to return an error.
It takes more effort to wrap a handler for a specific exception because there was no need originally to write a handler in that place.
You can just map your logging in between:
foo().map_err(|e| {log(e); e}).bar()
You can just macroexpand ? and do that (although I don't know that there are tools doing macroexpansion currently).
> I don't know what ? really does
It's really nothing special, `a?` simply expands to:
match a {
Ok(val) => val,
Err(err) => {
return Err(From::from(err))
}
}
> also if the funcitons throw exceptions instead of returning errors in other languages?
Ok, that's what I expected
> ?
I meant if I have foo().bar() in C# or Java and foo() throws it's equally hard to change the code to add error handling in between since I would need to add a try/catch clause and rethrow the error.