Go – about errors .

By | 05/04/2018

The golang come with a fair amount of functions end up returning errors like values.
The golang errors functions looking like this:

You can use the errors package and that implements functions to manipulate errors.
The official golang example:

You can see how is created the new custom errors using the New function:

The fmt package formats an error value by calling its Errorf() string method, see example:

You can add more information about the error using struct type and fields.
The error type is an interface type and can be used into this way.

And an error variable represents any value that can describe itself as a string, see example:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.