Donald Feury

errors

Error Chains

YouTube Video

Go added a neat feature in 1.13 that they call error chains

Errors can now implement a method called Unwrap that should return another error. Typically, this is an error that occurred further down in the call stack.

It is very common in go to have errors get tossed further and further back up the call stack as functions resolve, until its finally handled properly. Error chains allow you to carry a series of errors all the way back up the call stack more easily.

They added two new functions in the errors package to interact with this concept, Is and As

Is takes a argument of an error and another error, returns true if any instance of the second error occurs in the first error's chain, and false otherwise.

As takes the same arguments, but sets the value of the second argument equal to the error that was found in the first error's chain if it was present.

Check out the video to see the concept in action.

If you liked it and want to know when I post more, be sure to subscribe and thank ya'll again for your time!

#go #golang #errors

Go Error Handling

YouTube Video

Error handling in Go is pretty straight forward. There are no exceptions, there are no try catch blocks, there is only ERROR.

Error is a type like any other primitive built into the language, like a int or a string. This makes error handling, while a tad verbose, very straight forward and easy to understand.

Check it out and let me know what ya'll think. Any feedback is greatly appreciated.

If you liked it and want to know when I post more, be sure to subscribe and thank ya'll again for your time!

#go #golang #errors