golang中的panic需要recover捕获,不然程序就会挂掉
package main
import "fmt"
func main() {
f1()
fmt.Println("Returned")
}
func f1() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
}
}()
g1(0)
}
func g1(i int) {
if i > 1 {
panic(fmt.Sprintf("%v", i))
}
g1(i + 1)
}