Closed vlappa closed 1 year ago
Can you, please, elaborate, how would you use this error value in menu callback?
You don't need to return an error: and in fact in a callback you can't since the callback is called by the system not by you.
The solution for handling errors in callbacks is to use a closure, e.g.,
widget.SetCallback(func() {
if err := doSomething(); err != nil {
app.handleError(err) // app is some type that's been captured by the closure
}
})
I see, thx. Callbacks are a bit magical to me still. I'm starting to see how closures can be useful.
Handling errors is important in Go, but callbacks are expected to be of type func() in go-fltk. Shouldn't that become: func() error?
https://github.com/pwiecz/go-fltk/blob/main/menu.go#L48