3 ms·
I think you missed his point. >Some errors can only be identified by value and others can only be identified by type Let's say I'm reading a csv file, and I n
by nemothekid 10y ago
I think you missed his point.
>Some errors can only be identified by value and others can only be identified by type
Let's say I'm reading a csv file, and I need to check whether I'm done reading the file - I'd do something like so:
if _, err := csvReader.Read(); err == io.ErrEOF {
quit()
}
However (I can't think of an example off the top of my head), there are many library that make you check the error type to find out what went wrong.
if c_err, ok := err.(LibError); ok {
c_err.Code
}
I commonly see this version in libraries that need to return an error with a non-static message (such as the `hostname goolge.com could not be reached`).