>> If you set the var statement outside the main func, the issue is gone 
because err is then a "global" var.

Not quite correct.

This is how it work and why `err` is used:


package main
import "fmt"
type closure03 struct {
        err *error
        f   func() error
}
func (c *closure03) fn() {
        *c.err = c.f()
}
func main() {
        var err error

        closure03 := &closure03{err: &err, f: f}

        g := closure03.fn

        g()
        fmt.Println(err)
}
func f() error {
        return fmt.Errorf("Some error occurred")
}


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


-- 
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