Most cleanup functions, especially those related to the IO operations, return an error
, and normally we'd prefer to defer
their execution in case if we'd not forget to call them when we're done with acquired resources. For example, at some point in the code we might write something like this:
var r *SomeResource
var err error
if r, err = Open(/* parameters */); err != nil {
return nil, err
}
defer r.Close() // This might return an error
It seems that if Close
function returns an error, it'll be ignored. How can we gently process the returned error
from such a function?