Don’t Panic! Handle Your Errors
Overview
In this chapter, we will be looking at various code snippets from the Go standard packages to get an understanding of Go’s idiomatic way of performing error handling. We will also look at how to create custom error types in Go and see more examples in the standard library.
By the end of this chapter, you will be able to distinguish between the different types of errors and compare error handling and exception handling. You will also be able to create error values, panic()
, and properly recover after a panic and handle your errors. Lastly, we will briefly discuss adding context to our errors through error wrapping.