Nice. I think we can generalize to accepting any func() that we may want to prevent panicking: https://play.golang.org/p/Gj1e0PllFu When signature is not exactly func(), e.g. func bad2(x int), then wrap in a closure.
It kind of reminds me of template.Must <https://golang.org/pkg/text/template/#Must>, just doing the opposite thing. Cheers Val On Friday, March 24, 2017 at 9:50:47 AM UTC+1, Henry wrote: > > Thanks for the reply, Andrei. Your solution works. > > Jerome's solution doesn't work. I think Jerome and I made the wrong > assumption that recover returns an error. Apparently, recover returns an > interface. That's why recover assignment to error doesn't work. > > Thanks again for all the replies. > > -- 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.