If you want an anonymous defer function to have the same effect as a 
separate function, ensure that they accept the same parameters. To continue 
your example, this third version produces the same result as your first 
version, but uses an anonymous defer function.

https://play.golang.org/p/oqQC_susbH

func foo() {
var err error

defer func(err error) {
if err == nil {
println("err is nil")
} else {
println(err.Error())
}
}(err)

err = errors.New("hello")

return
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to