4 ms·
If you want to set a breakpoint on the error then I guess that's not possible in your form. I don't know what ? really does but I guess it somehow short-circuit
by Matthias247 10y ago
If you want to set a breakpoint on the error then I guess that's not possible in your form. I don't know what ? really does but I guess it somehow short-circuits the current block in the error form and returns the error.
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).
- junke 10y agoThat's trivially possible in the Go version because you paid the cost of adding explicit error handling upfront. 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.
- masklinn 10y ago> If you want to set a breakpoint on the error then I guess that's not possible in your form. 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 ?
- Matthias247 10y ago> It's really nothing special, `a?` simply expands to: 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.
- deleted 10y ago[deleted]
- stouset 10y ago> I don't know what ? really does 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.
- Retra 10y ago>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 You can just map your logging in between: foo().map_err(|e| {log(e); e}).bar()