Introduction

Hello! Today's expedition is about understanding Go's error messages. We'll examine how these error messages work, their structure, and the most common types that we're likely to encounter. Let's get started!

An Overview of Go Error Messages

Go handles errors in a way that's somewhat different from other languages. Here, an error is a predefined interface, which isn't meant to signal an exception but to be a standard return type. When your Go code encounters a situation it doesn’t know how to handle, the typical response is to return an error to signal this to the caller of the function.

Structure of Go Error Messages

Go's error messages comprise the following:

  1. Description: This string describes what went wrong.

To illustrate, let's consider this code error:

The code:

The error:

Although the error message provides not much of insight, it's sufficiently direct for us to understand that there's a missing parenthesis.

For this error:

  • Description is syntax error: unexpected newline in argument list; possibly missing comma or )

Every error contains a description to help you understand what's not right.

Exploring Go Error Types: Syntax Errors
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal