1 pages tagged with "go"
Error handling in defer
October 07, 2023
I see periodically people handling errors in deferred calls like this:
func Do() (r Result, err error) {
// ...
defer func() {
err = multierr.Append(err, f.Close())
}()
// ...
}
or another variant:
func Do() (err error) {
// ...
defer func() {
err1 = f.Close(…
read more