I had a “wtf” moment when using Go around panic() and recover()
I was so surprised by the design choice to need to put recover in in deferred function calls. It’s crazy to smush together the error handling and normal execution code.
replies(2):
I was so surprised by the design choice to need to put recover in in deferred function calls. It’s crazy to smush together the error handling and normal execution code.
func Foo() { try { maybePanic() } catch (err any) { doSomething(err) }
.. more code
}vs
func Foo() { defer func() { if err := recover(); err != nil { doSomething(err) } }()
maybePanic()
.. more code
}