Created
October 17, 2014 15:59
-
-
Save wheaties/5cd55e26d5600b789b39 to your computer and use it in GitHub Desktop.
Capture defer error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Capture struct{ | |
closer *Closer | |
err error | |
} | |
func (cap Capture) Close() error { | |
cap.err = cap.closer.Close() | |
return cap.err | |
} | |
func DoSomething(cl *ReadCloser) (thing, error) { | |
var cap = Capture{cl, nil} | |
defer cap.Close() | |
out, err := GetThing(cl, "something") | |
if err != nil { | |
return nil, err | |
} | |
return out, cap.err | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://blog.golang.org/defer-panic-and-recover, doesn't work.