try

package
v0.0.0-...-ac7d4c8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 4 Imported by: 0

README

try包

  • 保证程序不会抛出异常
  • try.Go让协程更安全执行

Documentation

Overview

异常处理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(fn func(), f ...ExceptionHandlerFunc)

执行一个可能出现异常的程序段

func Go

func Go(fn func(), f ...ExceptionHandlerFunc)

开启一个可以捕捉异常的安全协程,建议程序中全部使用此方法启动协程 必须对协程做异常处理,catch里面不能再次Throw

func SetExceptionHandler

func SetExceptionHandler(fn ExceptionHandlerFunc)

设置未能捕捉的异常的统一处理方法

func Throw

func Throw(e interface{}, args ...interface{})

抛出一个异常,【请谨慎使用,有可能因此造成程序退出】 参数:Exception 或者其它错误 如果第一个参数是Exception,则args可以增加title和data 例如:Throw(&ExceptionBase{}, "未知异常","异常内容")

func ThrowFatal

func ThrowFatal(title string, errs ...interface{})

抛出致命级别错误

func ThrowFatalf

func ThrowFatalf(title string, format string, errs ...interface{})

抛出致命级别错误

func ThrowInfo

func ThrowInfo(title string, errs ...interface{})

抛出信息级别错误

func ThrowInfof

func ThrowInfof(title string, format string, errs ...interface{})

抛出信息级别错误

func ThrowWarn

func ThrowWarn(title string, errs ...interface{})

抛出警告级别错误

func ThrowWarnf

func ThrowWarnf(title string, format string, errs ...interface{})

抛出警告级别错误

Types

type Exception

type Exception interface {
	Init(msg string, data interface{})
	Name() string         //异常名称
	GetMsg() string       //异常消息
	GetData() interface{} //异常数据
	String() string       //异常数据字符串输出
	Stack() string        //堆栈
}

异常接口

type ExceptionBase

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

默认异常

func (*ExceptionBase) GetData

func (this *ExceptionBase) GetData() interface{}

获取异常内容

func (*ExceptionBase) GetMsg

func (this *ExceptionBase) GetMsg() string

标题

func (*ExceptionBase) Init

func (this *ExceptionBase) Init(msg string, data interface{})

创建异常

func (*ExceptionBase) Name

func (this *ExceptionBase) Name() string

func (*ExceptionBase) Println

func (this *ExceptionBase) Println(a ...interface{})

func (*ExceptionBase) Stack

func (this *ExceptionBase) Stack() string

获取异常产生的堆栈

func (*ExceptionBase) String

func (this *ExceptionBase) String() string

获取异常文本

type ExceptionFatal

type ExceptionFatal struct {
	ExceptionBase
}

致命级别错误(不可输出到前台)-----------

func (*ExceptionFatal) Name

func (this *ExceptionFatal) Name() string

type ExceptionHandlerFunc

type ExceptionHandlerFunc func(Exception)

异常处理方法

type ExceptionInfo

type ExceptionInfo struct {
	ExceptionBase
}

提示异常-------------------------

func (*ExceptionInfo) Name

func (this *ExceptionInfo) Name() string

--

type ExceptionRuntime

type ExceptionRuntime struct {
	ExceptionBase
}

运行时异常-------------------------

func (*ExceptionRuntime) Name

func (this *ExceptionRuntime) Name() string

type ExceptionWarn

type ExceptionWarn struct {
	ExceptionBase
}

警告级别错误(可输出到前台)--------------

func (*ExceptionWarn) Name

func (this *ExceptionWarn) Name() string

Jump to

Keyboard shortcuts

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