I have an array of some data which I want to map in []string
. I can do it in 2 ways:
a)
// someData
s := someData.([]string)
In this case, the execution would stop after listing the error on the console.
b)
// someData
s, ok := someData.([]string)
In this case, no errors would occur but s will have its zero-value
I want to log the errors in such type assertion failure cases without stopping the execution. However, when I am using type (b), I cannot see the error details.
The only solution I can think is to use reflect.TypeOf
and print both the types.
Is there any other way we can get the error when using solution (b)?