Go has a builtin type for errors. In Go, an error is the last return value (They have type error).
The line errors.New
creates a new error with a message. If there is no error, you can return the nil
value.
Example
Errors
The function do()
is called, which returns an error. To use Go errors, you must include the package errors: import "errors"
.
package main |
1 | $ go run example.go |
You can combine both the return values:
r, e := do() |
Leave a Reply