Summary
In this chapter, we looked at the different types of errors that you will encounter while programming, such as syntax, runtime, and semantic errors. We focused more on runtime errors since they are challenging to debug.
Then, we examined the difference between various language philosophies when it comes to dealing with errors. We saw how Go’s syntax for errors is simpler to understand compared to the exception handling that various languages utilize.
An error in Go is a value. Values can be passed around to functions. Any error can be a value, so long as it implements the error interface type. We learned how easily we can create errors. We also learned that we should name our error values so that they start with Err
, followed by a descriptive camel case name.
Next, we discussed panics and the similarities between a panic and an exception. We also discovered that panics are pretty similar to exceptions; however, if panics aren’t handled, they will cause...