Standard library / reflect

reflect.Value.FieldByIndexErr()

Follow a field path and report an error if traversal requires dereferencing a nil embedded pointer. Invalid field indexes or kinds can still panic. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) FieldByIndexErr(index []int) (Value, error)

Parameters & Attributes

NameTypeDescription
index[]intSequence of zero-based field indexes through nested structs.

Return Value

(Value, error)

Follow a field path and report an error if traversal requires dereferencing a nil embedded pointer.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  type A struct{ X int }  type B struct{ *A }  _, err := reflect.ValueOf(B{}).FieldByIndexErr([]int{0, 0})  fmt.Println(err != nil)}
Go Reference