panic的使用
package main
import "fmt"
func tryRecover() int {
defer func() {
r := recover()
if err, ok := r.(error); ok {
fmt.Println("Error occurred", err)
} else {
panic((fmt.Sprintf("i don't know what to do: %v", r)))
}
}()
a := 0
panic(123)
return a
}
func main() {
tryRecover()
}