Consider the following code:
list := strings.Split(somestring, "\n")
Let's say this returns a list or slice of three elements. Then, if you try to access something outside the range of the slice:
someFunction(list[3])
The program can crash because of a nil pointer. Is there some way in Golang to handle a nil pointer exception so that the program won't crash and can instead respond appropriately?
len(list)before accessing an index, which will prevent an out of bounds error. I would not lean on panic/recover (as suggested) for something like this.