errors

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package errors 封装的错误处理包

使用New创建一个FushinError对象 使用errors.Recover(recover())接收goroutine的recover信息 当Recover一个FushinError时不保留堆栈信息 只记录goroutine id 使用errors.Panic()创建一个带有FushinError的panic

func TestFushinError() {
	defer func() {
		rec := Recover(recover())
		if rec.HasRecover() {
			t.Log(rec.GetTrace())
			t.Log(rec.GID())
		} else {
			t.Log(rec)
		}
	}()
	// 模拟err
	err := New("this is an error")
	t.Log(err.Error())
	// 模拟panic
	Panic("this is a panic")
	// panic
	panic("panic2")
}

Package errors

Package errors

Package errors

Package errors

Index

Constants

View Source
const (
	TraceSIZE = 1 << 20
)

Variables

This section is empty.

Functions

func Panic added in v1.1.0

func Panic(s string)

Types

type Errors

type Errors interface {
	Error() string
	ID() string
	GetTrace() string
	HasError() bool
	HasRecover() bool
}

type FushinError added in v1.1.0

type FushinError struct {
	// contains filtered or unexported fields
}

FushinError 包含goroutineID的可追溯错误

func New added in v1.1.0

func New(s string) FushinError

func Recover added in v1.1.0

func Recover(recover interface{}) FushinError

Recover must pass a recover func 当Recover一个FushinError时不保留堆栈信息 只记录goroutine id

func (FushinError) Error added in v1.1.0

func (f FushinError) Error() string

func (FushinError) GID added in v1.1.0

func (f FushinError) GID() string

GID 返回recover堆栈的goroutine id

func (FushinError) GetTrace added in v1.1.0

func (f FushinError) GetTrace() string

GetTrace 获取stack堆栈

func (FushinError) HasError added in v1.1.0

func (f FushinError) HasError() bool

HasError 是否有错误

func (FushinError) HasRecover added in v1.1.0

func (f FushinError) HasRecover() bool

func (FushinError) ID added in v1.1.0

func (f FushinError) ID() string

ID 获取错误的uuid

type TryInstance added in v1.1.1

type TryInstance struct {
	// contains filtered or unexported fields
}

func Try added in v1.1.1

func Try(f func()) (ti *TryInstance)

func (*TryInstance) Catch added in v1.1.1

func (t *TryInstance) Catch(f func(exception interface{})) *TryInstance

Catch Try实例拥有的Catch方法 附带参数exception为出错时包含的错误

func (*TryInstance) Finally added in v1.1.1

func (t *TryInstance) Finally(f func())

Finally 总是最后运行 Finally中执行的函数未被recover()需要保证不会panic

Jump to

Keyboard shortcuts

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