Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIgnore = errors.New("error can be ignored")
var ErrorHandlers = []func(error){ func() func(err error) { limiter := rate.NewLimiter(rate.Every(time.Millisecond), 1) return func(err error) { _ = limiter.Wait(context.Background()) } }(), }
ErrorHandlers is a list of functions which will be invoked when a nonreturnable error occurs. should be packaged up into a testable and reusable object.
Functions ¶
func HandleError ¶
func HandleError(err error)
HandleError is a method to invoke when a non-user facing piece of code cannot return an error and needs to indicate it has been ignored. Invoking this method is preferable to logging the error - the default behavior is to log but the errors may be sent to a remote server for analysis.
func IsAll ¶ added in v1.2.72
IsAll reports whether any error in err's tree matches all target in targets.
func IsAny ¶ added in v1.2.72
IsAny reports whether any error in err's tree matches any target in targets.
func Mark ¶
Mark returns an error with the supplied errors as marks. If err is nil, return nil. marks take effects only when Is and '%v' in fmt. Is returns true if err or any marks match the target.
Example ¶
package main
import (
"errors"
"fmt"
errors_ "github.com/searKing/golang/go/errors"
)
func main() {
err := errors.New("err")
mark1 := errors.New("mark1")
mark2 := errors.New("mark2")
mark3 := errors.New("mark3")
me := errors_.Mark(err, mark1, mark2)
fmt.Println(me)
if errors.Is(me, err) {
fmt.Println("err is err")
}
if errors.Is(me, mark1) {
fmt.Println("err is mark1")
}
if errors.Is(me, mark2) {
fmt.Println("err is mark2")
}
if errors.Is(me, mark3) {
fmt.Println("err is mark3")
}
if errors.Is(me, nil) {
fmt.Println("err is nil")
}
}
Output: err err is err err is mark1 err is mark2
func Multi
deprecated
Deprecated: Use errors.Join instead since go1.20.
Example ¶
package main
import (
"errors"
"fmt"
)
func main() {
err1 := errors.New("err1")
err2 := errors.New("err2")
err3 := errors.New("err3")
err := errors.Join(err1, err2)
fmt.Println(err)
if errors.Is(err, err1) {
fmt.Println("err is err1")
}
if errors.Is(err, err2) {
fmt.Println("err is err2")
}
if errors.Is(err, nil) {
fmt.Println("err is nil")
}
if errors.Is(err, err3) {
fmt.Println("err is err3")
}
}
Output: err1 err2 err is err1 err is err2
Types ¶
This section is empty.