Why does a call to defer func() { recover() }()
successfully recover a panicking goroutine, but a call to defer recover()
not?
As an minimalistic example, this code doesn't panic
package main
func main() {
defer func() { recover() }()
panic("panic")
}
However, replacing the anonymous function with recover directly panics
package main
func main() {
defer recover()
panic("panic")
}