Hi,
I have a number of cases where I have to handle typed errors. I have been
doing this previoiusly
err :=SomeFunctionCall()
if err != nil{
switch e := err.(type){
case sometype:
//do something
case someothertype:
//do something else
default:
//do default
}
}
However, it occurred to me that I can just do this...
err :=SomeFunctionCall()
switch e := err.(type){
case nil:
break
case sometype:
//do something
case someothertype:
//do something else
default:
//do default
}
I guess this will be less efficient because it will involve some reflection
in cases where I imagine the initial check that error is not nil will be
less expensive. Is this correct?
Apart from this, is there any other reason that this would not be a
recommended way to handle the nil error case?
Many thanks
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.