4 ms·
The biggest mistake I think go made was not to include codes or domains. The error you get back is... a string. So you have to write tons of if statements jus
by pixelrevision 7y ago
The biggest mistake I think go made was not to include codes or domains. The error you get back is... a string. So you have to write tons of if statements just to return a bunch of errors you can’t handle.
- donatj 7y agoError is an interface. The default one may be a string but you can implement your open error with whatever extras you would like.
- CameronNemo 7y agoRight but then you need to use errors.as to match against it, rather than being able to do pattern matching. And there is no inheritance, no ability to generalize errors into a group.
- donatj 7y agoYou can totally just type assert your custom error type to check for it. If it's the only type of error your method returns you don't even need to, just define your return type as your custom error type.