Go – about errors .
The golang comes with a fair amount of functions end up returning errors like values. The golang errors function looking like this:
1 2 3 4 5 | func (ex *StructExample) Function() (string, error) bytes, err := StructExample.Function() if err != nil { // this process the error of StructExample } |
You can use the errors package and that implements functions to manipulate errors. The official golang example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | package main import ( "errors" "fmt" ) func main() { err := errors.New("emit macho dwarf: elf header corrupted") if err != nil { fmt.Print(err) } } |
You can see how it created the new custom errors using the New function:… Read More »