Handling Errors
At this point your application handles errors by defining error strings, using the function fmt.Errorf from package fmt. This is a valid approach for small applications, but it’s harder to maintain as your application grows in complexity. For instance, relying only on comparing the error message isn’t a resilient method as the error message may change.
As an alternative, in Developing the Initial Version of colStats, you handled errors by defining error values as exported variables. You can use this approach here to handle simple errors, such as validating input parameters. Add a file errors.go to your project and edit it. Add the package definition and the import section. For this file, you’re using the package errors to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access