Go Language Error Handling: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
m (Ovidiu moved page Go Error Handling to Go Language Error Handling without leaving a redirect)
Line 1: Line 1:
=Internal=
=Internal=
* [[Go_Language#Error_Handling|Go Language]]
* [[Go_Language#Error_Handling|Go Language]]
=Overview=
A common error generation pattern in Go is that function return an error instance as the second return value.
The returned error instance is implements the <code>error</code> interface:
<syntaxhighlight lang='go'>
type error interface {
  Error() string
}
</syntaxhighlight>
=Organizatorium=
=Organizatorium=



Revision as of 22:26, 30 August 2023

Internal

Overview

A common error generation pattern in Go is that function return an error instance as the second return value.

The returned error instance is implements the error interface:

type error interface {
  Error() string
}

Organizatorium

Create an error:

errors.New("at least three arguments are required")

TO DEPLETE

These are documents produced by the previous attempt. Process, merge into this document, and deplete: Go Concepts - Error Handling