Get the latest tech news
Don't just check errors, handle them gracefully (2016)
This post is an extract from my presentation at the recent GoCon spring conference in Tokyo, Japan. Errors are just values I’ve spent a lot of time thinking about the best way to handle errors in Go programs.
If someone asks you to export an error value from your package, you should politely decline and instead suggest an alternative method, such as the ones I will discuss next. For example, interactions with the world outside your process, like network activity, require that the caller investigate the nature of the error to decide if it is reasonable to retry the operation. The key here is this logic can be implemented without importing the package that defines the error or indeed knowing anything about err ‘s underlying type–we’re simply interested in its behaviour.
Or read this on Hacker News