Just started using Golang. I think that it is idiomatic to declare an error variable and use it in your error structure to determine what went wrong, as is done in strconv.go. There, ErrRange
and ErrSyntax
is declared, and when appropriate, references to those are stored in NumError
structs when they return. I think that the reason is because then the address of the reference to the error stored in NumError
can be compared with the ErrRange
and ErrSyntax
variables to determine which type of error was returned.
Are there "standard" such declared error types? In Java, for example, you have things like java.lang.IllegalArgumentException
. Is there, for instance, ErrArgument
or ErrUnsupportedOperation
that I can use in my own code instead of creating new error variables that mean the same thing every time?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…