Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created September 27, 2018 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChimeraCoder/9fdef30e84ab374b612533ae4fd06873 to your computer and use it in GitHub Desktop.
Save ChimeraCoder/9fdef30e84ab374b612533ae4fd06873 to your computer and use it in GitHub Desktop.
example of a defer that uses named error return params
func CalculateThing() (result int, err error) {
defer func() {
if err != nil {
monitoringSrv.HandleErr("CalculateThing", err)
}
}()
var a, b int
a, err = doA()
if err != nil {
return
}
b, err = doB(a)
if err != nil {
return
}
result, err = doC(b)
return
}
func CalculateThing2() (result int, err error) {
handle err {
monitoringSrv.HandleErr("CalculateThing", err)
}
a := check doA()
b := check doB(a)
result = check doC(b)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment