9. Errors
This chapter covers the benefits of how Go’s error model results in more reliable code. We cover how to handle basic errors and return errors as an interface that satisfies the error type. Additionally, we also discuss concepts such as custom error types, panics, recovering from panics, and sentinel errors.
Errors as Values
A lot of languages use the concept of exceptions.1 When something goes wrong, an exception is thrown. This exception then needs to be caught. When catching an exception, you have the opportunity to log the exception and possibly move on with an alternate code path or reraise the exception to let the developer upstream deal with the problem.
1. https://en.wikipedia.org/wiki/Exception_handling
Listing 9.1 shows an ...
Get Go Fundamentals: Gopher Guides now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.