errors
Package errors implements functions to manipulate errors.
Index
Functions
func New
1func New(text string) errorNew returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.
Example
1err := errors.New("emit macho dwarf: elf header corrupted")
2if err != nil {
3 fmt.Print(err)
4}Output
emit macho dwarf: elf header corrupted
Example
The fmt package's Errorf function lets us use the package's formatting features to create descriptive error messages.
1const name, id = "bimmler", 17
2err := fmt.Errorf("user %q (id %d) not found", name, id)
3if err != nil {
4 fmt.Print(err)
5}Output
user "bimmler" (id 17) not found