阅读(2685) (0)

GoFrame 错误处理-常用方法

2022-03-30 09:21:16 更新

错误创建

New/Newf

  • 说明:用于创建一个自定义错误信息的​error​对象,并包含堆栈信息。
  • 格式:

New(text string) error
Newf(format string, args ...interface{}) error

Wrap/Wrapf

  • 说明:用于包裹其他错误​error​对象,构造成多级的错误信息,包含堆栈信息。
  • 格式:

func Wrap(err error, text string) error
func Wrapf(err error, format string, args ...interface{}) error

NewSkip/NewSkipf

  • 说明:用于创建一个自定义错误信息的​error​对象,并且忽略部分堆栈信息(按照当前调用方法位置往上忽略)。高级功能,一般开发者很少用得到。
  • 格式:

func NewSkip(skip int, text string) error 
func NewSkipf(skip int, format string, args ...interface{}) error

错误码相关方法

func NewCode(code int, text string) error
func NewCodef(code int, format string, args ...interface{}) error
func NewCodeSkip(code, skip int, text string) error
func NewCodeSkipf(code, skip int, format string, args ...interface{}) error
func WrapCode(code int, err error, text string) error
func WrapCodef(code int, err error, format string, args ...interface{}) error