This chapter only introduces some commonly used methods. For a complete list of error methods, please refer to the interface documentation: https://pkg.go.dev/github.com/gogf/gf/v2/errors/gerror
New/Newf
-
Description: Used to create a custom error message
error
object, including stack information. -
Format:
// New creates and returns an error which is formatted from given text.
New(text string) error
// Newf returns an error that formats as the given format and args.
Newf(format string, args ...interface{}) error
Wrap/Wrapf
-
Description: Used to wrap other
error
objects, constructing multi-level error messages, including stack information. -
Format:
// Wrap wraps error with text. It returns nil if given err is nil.
// Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
func Wrap(err error, text string) error
// Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier.
// It returns nil if given `err` is nil.
// Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
func Wrapf(err error, format string, args ...interface{}) error
NewSkip/NewSkipf
-
Description: Used to create a custom error message
error
object, and ignore part of the stack information (ignoring upwards from the current method call location). Advanced functionality, rarely used by general developers. -
Format:
// NewSkip creates and returns an error which is formatted from given text.
// The parameter `skip` specifies the stack callers skipped amount.
func NewSkip(skip int, text string) error
// NewSkipf returns an error that formats as the given format and args.
// The parameter `skip` specifies the stack callers skipped amount.
func NewSkipf(skip int, format string, args ...interface{}) error
WrapSkip/WrapSkipf
-
Description: Similar to the
Wrap/Wrapf
methods, but ignores part of the stack information. -
Format:
// WrapSkip wraps error with text. It returns nil if given err is nil.
// The parameter `skip` specifies the stack callers skipped amount.
// Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
func WrapSkip(skip int, err error, text string) error
// WrapSkipf wraps error with text that is formatted with given format and args. It returns nil if given err is nil.
// The parameter `skip` specifies the stack callers skipped amount.
// Note that it does not lose the error code of wrapped error, as it inherits the error code from it.
func WrapSkipf(skip int, err error, format string, args ...interface{}) error