You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
412 B

package main
import (
"errors"
"fmt"
)
func funcA() error {
defer func() {
if p := recover(); p != nil {
fmt.Printf("panic recover! p: %v", p)
//debug.PrintStack()
}
}()
return funcB()
}
func funcB() error {
// simulation
panic("foo")
return errors.New("success")
}
func main() {
err := funcA()
if err == nil {
fmt.Printf("err is nil\n")
} else {
fmt.Printf("err is %v\n", err)
}
}