This article is an exploration of how to improve error handling in Go. I address here some of the issues while others are left with open questions and some ideas. And, spoiler alert, I do love error handling in Go as it is now. I don’t want to replace it with anything like exceptions, but I want to make it slightly better.
I’m going to limit all solutions to what we already have in the language. I’m not talking about any language changes or making a new programming language out of Go. Everything we do here must be possible to shape into a ready-to-use pure Go package.
It looks like something other languages call “tuple,” but in Go, there is no such type you can operate on. Instead, these are two separate values returned.
This all is important because that’s how error handling in Go works. The convention is to return the error as the last result value from the functions that may fail: