Documentation ¶
Index ¶
- func As(err error, target interface{}) bool
- func Cause(err, cause error) error
- func CauseStr(err error, cause string) error
- func Is(err, target error) bool
- func New(e string) error
- func Recover(err *error)
- func RecoverStack(err *error)
- func Unwrap(err error) error
- func Wrap(str string, err error) error
- type Const
- type Errordeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v1.3.0
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
An error type might provide an As method so it can be treated as if it were a different error type.
As panics if target is not a non-nil pointer to either a type that implements error, or to any interface type.
This function is an alias to errors.As in the standard library.
func Cause ¶
Cause wraps an error in a another error. This returns nil if `cause` is nil. If `err` is nil `cause` is returned.
func Is ¶ added in v1.3.0
Is reports whether any error in err's chain matches target.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
An error type might provide an Is method so it can be treated as equivalent to an existing error.
This function is an alias to errors.Is in the standard library.
func New ¶ added in v1.3.0
New returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.
This function is an alias to New in the standard library.
func Recover ¶ added in v1.4.0
func Recover(err *error)
Recover recovers from a panic. This function must be deferred. Usage:
func someFunction() (err error){ defer Recover(&err) // do stuff }
func RecoverStack ¶ added in v1.5.0
func RecoverStack(err *error)
RecoverStack recovers from a panic and gets the stack trace. This function must be deferred. Usage:
func someFunction() (err error){ defer RecoverStack(&err) // do stuff }
func Unwrap ¶ added in v1.3.0
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.
This function is an alias to errors.Unwrap in the standard library.