Go Language Error Handling: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
A common error generation pattern in Go is that function return an error instance as the second return value.
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> [[Go_Interfaces#Overview|interface]]:
<span id='Error_Interface'></span>The returned error instance is implements the <code>error</code> [[Go_Interfaces#Overview|interface]]:


<syntaxhighlight lang='go'>
<syntaxhighlight lang='go'>
Line 13: Line 13:
}
}
</syntaxhighlight>
</syntaxhighlight>
The <code>error</code> interface is a [[Go Concepts - Lexical Structure#Pre-Declared_Identifiers|pre-declared type identifier]].


=Organizatorium=
=Organizatorium=

Revision as of 22:28, 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
}

The error interface is a pre-declared type identifier.

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