为什么defer fun()中返回的error,调用的地方,获取到位nil?
func call1(x string) (string, error) {
fmt.Println("into call1")
var reback string \= ""
canset := false
defer func() (string, error) {
i := recover()
if i != nil {
fmt.Println("异常信息捕获:", i, "反射到的y是否可以编辑?", canset)
j := fmt.Sprintf("%s", i)
//这里返回的异常,外层无法拦截到?
return "", errors.New("异常信息捕获:" \+ (j))
} else {
return reback, nil
}
}()
a := x
y := reflect.ValueOf(x)
canset \= y.CanSet()
y.SetString("10")
b := x
//报错了 reflect.flag.mustBeAssignable using unaddressable value reback \= "反射修改前:" \+ a \+ "反射修改后:" \+ b
fmt.Println(reback)
return reback, nil
}