package main
import (
"fmt"
"reflect"
)
func main() {
test()
fmt.Println("main done !")
}
func test() {
defer func() {
fmt.Println("test defer ...")
if err := recover(); err != nil {
fmt.Println("err ", err)
fmt.Println(reflect.TypeOf(err))
errStruct := reflect.ValueOf(err)
fmt.Println(errStruct.FieldByName("name"))
fmt.Println(errStruct.FieldByName("msg"))
}
}()
fmt.Println("test func ...")
type ErrStruct struct {
name string
msg string
}
errStruct := ErrStruct{"aaaa", "99999"}
panic(errStruct)
fmt.Println("test done !")
}