7 Error management

This chapter covers

  • Understanding when to panic
  • Knowing when to wrap an error
  • Comparing error types and error values efficiently since Go 1.13
  • Handling errors idiomatically
  • Understanding how to ignore an error
  • Handling errors in defer calls

Error management is a fundamental aspect of building robust and observable applications, and it should be as important as any other part of a codebase. In Go, error management doesn’t rely on the traditional try/catch mechanism as most programming languages do. Instead, errors are returned as normal return values.

This chapter will cover the most common mistakes related to errors.

7.1 #48: Panicking

It’s pretty common for Go newcomers to be somewhat confused about error handling. In Go, ...

Get 100 Go Mistakes and How to Avoid Them now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.