Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by typical_gopher on Sunday November 06, 2022 @12:19AM
(#33488947)
> C++ and Java exceptions have non-local flow and it's hard to determine what function can throw what, so if you do want to add error handling cases you would have to inspect every function to know if it throws or not
In general I agree with you, but Rust is already having this problem by people making liberal use of unwrap.
Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by potatochup on Sunday November 06, 2022 @11:59AM
(#33494613)
I haven't seen such a problem with unwrap. Newer people use it but are quickly taught to use Err instead. The only times I use it is unreachable!()
Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by nyanpasu64 on Sunday November 06, 2022 @01:00AM
(#33489169)
C++ exceptions and Rust Anyhow errors lack stack traces by default, whereas Java exceptions capture them by default, aiding debugging. I'm not sure if Rust spans satisfy the same requirements as stack traces; they seem more built around logging and asynchronous execution, than error handling and synchronous code.
Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by jamincan on Sunday November 06, 2022 @07:52AM
(#33492039)
I believe the backtrace API was added to stable rust with the most recent release, and so anyhow backtraces should now be available outside of nightly.
Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by Animats on Sunday November 06, 2022 @01:17AM
(#33489719)
After several false starts, Rust mostly got this right with returning
Result<usefulresult, Error>
from most functions, and using "?" for "If the result of this is Error, do a return of the error". There's also a thing where you can write foo().context("useful info about foo")?
and pass some more info with the error.Plus, most things that work like "open" close when their scope closes, so you don't need all that "defer" stuff.
I would have liked a good error hierarchy like Python 2 had, where there was a clear distinction between program-is-broken errors and errors due to external causes. But Rust didn't get that at the beginning, and now it's too late.
Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by tveita on Sunday November 06, 2022 @07:25AM
(#33491836)
I believe the Context trait is from Anyhow, not part of the base Error trait in Rust.
anyhow::Error really does a good job of smoothing out the finicky bits of Rust error handling, it feels and reads a lot better than Go code to me.
Re:Thoughts on the “Guard” Proposal for Go's Error Handling
by Animats on Sunday November 06, 2022 @12:23PM
(#33494913)
Yes, Context is part of Anyhow. That's a legacy problem. Something like Anyhow should have been the base of almost all errors, but it came too late. If you get error handling wrong at the start of a new language, it's really hard to make changes, because the old format gets baked into everything.
C++ and Java exceptions have non-local flow and it's hard to determine what function can throw what, so if you do want to add error handling cases you would have to inspect every function to know if it throws or not. Yeah, there's noexcept and checked exceptions but one was a late addition that legacy codebases don't use and the other everyone just does throw new RuntimeException(err) anyway.