package main
import "fmt"
func myRecover() {
if r := recover(); r != nil {
fmt.Println(r)
}
}
func main() {
defer func() {
myRecover()
}()
panic("The gas price is skyrocketing!")
}
The code above can not recover from the panic somehow the code below can.
package main
import "fmt"
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println(r)
}
}()
panic("The gas price is skyrocketing!")
}
It is so confusing. I want to know why.