diff --git a/get.go b/get.go index 46870b5..fe40344 100644 --- a/get.go +++ b/get.go @@ -1,6 +1,7 @@ package reflectutils import ( + "errors" "fmt" "reflect" "strings" @@ -30,6 +31,11 @@ func IsNil(i interface{}) bool { // Get value of a struct by path using reflect. func Get(i interface{}, name string) (value interface{}, err error) { // printv(i, name) + defer func() { + if r := recover(); r != nil { + err = errors.New(fmt.Sprint(r)) + } + }() if IsNil(i) { return diff --git a/set.go b/set.go index f994bf5..2c91798 100644 --- a/set.go +++ b/set.go @@ -31,6 +31,11 @@ var NoSuchFieldError = errors.New("no such field") // Set value of a struct by path using reflect. func Set(i interface{}, name string, value interface{}) (err error) { + defer func() { + if r := recover(); r != nil { + err = errors.New(fmt.Sprint(r)) + } + }() v := reflect.ValueOf(i)