3 ms·
I use golang quite a lot. The way this should be used is being ignored by all of the examples I have seen so far. When an error occurs people should be doing
by imetatroll 7y ago
I use golang quite a lot. The way this should be used is being ignored by all of the examples I have seen so far.
When an error occurs people should be doing what they already should be doing. That is to say, immediately log/wrap the error with context (file + line information) so that the error can be immediately found. Then if there are any callers of this failing function, they are the ones who should use try.
func A() error {
if err := do(); err != nil {
log(err)
return err
}
return nil
}
func B() error {
try(A())
return nil
}
To be honest though, I don't personally like this proposal.