Syntax

Go Handle an Error Syntax

In Go, handle an error: checks a returned error — if err != nil { return err }

Quick Answer

Syntax
if err != nil { return err }
GoSyntax

Handle an Error

Code example
if err != nil { return err }

Checks a returned error.

Learn More

How to handle an error in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Handle an Error Syntax

Use if err != nil { return err }.

Related Syntax References

Frequently asked questions

What is the Go syntax for handle an error?

Use this pattern: if err != nil { return err }

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify