Re:Declined Proposal: A built-in Go error check function, “try”
by erik_seaberg on Wednesday July 17, 2019 @02:14PM
(#20462426)
To be fair, reporting that cleanup also failed with a different error is inherently complicated, and so many people got the try-finally version wrong that Java finally added try-with-resources and Throwable#addSuppressed.
Re:Declined Proposal: A built-in Go error check function, “try”
by danielparks on Wednesday July 17, 2019 @10:49PM
(#20466265)
Definitely true. Mostly I just avoid using defer with Close, but I sometimes end up writing terrible stuff like:
defer func() {
err2 := f.Close()
if err == nil {
err = err2
}
}()
Not perfect, but better than nothing. I could use Wrapf to add information is err is already set. :-p
Quite the opposite. You have to explicitly ignore exceptions, whereas it’s easy to accidentally miss an error in Go. For example, how many times have you seen this?
Close() returns an error; this code ignores it.