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 ¶
Types ¶
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) HasRecover ¶ added in v1.1.0
func (f FushinError) HasRecover() bool
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
Click to show internal directories.
Click to hide internal directories.