errors

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 5 Imported by: 1

README

error

Go error Package

示例

examples/main.go

import "github.com/tinystack/errors"

err := errors.New("error test")
// fmt: main.exampleError(main.go:28): example err

err := errors.Newf("example err: %s", "error message")
// fmt: main.exampleErrorf(main.go:32): example err: error message

err := errors.New("simple err")
wrapErr :=  errors.Wrap(err, "wrap error message")
// fmt: main.exampleWrap(main.go:37): wrap error message | Caused: main.exampleWrap(main.go:36): simple err

err := errors.New("simple err")
return errors.Wrapf(err, "wrap: %s", "error message")
// fmt: main.exampleWrapf(main.go:42): wrap: error message | Caused: main.exampleWrapf(main.go:41): simple err

API

// 简单错误返回
errors.New(text string)

// format方式错误返回
errors.errors.Newf(format string, args ...interface{})

// 嵌套方式错误返回
errors.Wrap(err error, text string) *Error

// 嵌套+format方式错误返回
errors. Wrapf(err error, format string, args ...interface{}) *Error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Message  string
	Cause    error
	File     string `json:"file,omitempty"`
	Line     int    `json:"line,omitempty"`
	Function string `json:"function,omitempty"`
}

func Is

func Is(err error) (e *Error, ok bool)

func New

func New(text string) *Error

func Newf

func Newf(format string, args ...interface{}) *Error

func Wrap

func Wrap(err error, text string) *Error

func Wrapf

func Wrapf(err error, format string, args ...interface{}) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Wrap

func (e *Error) Wrap(err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL