代码拉取完成,页面将自动刷新
package ExceptionHelper
import (
"gitee.com/tym_hmm/hlog"
)
type Exception struct {
Code int
Message string
}
type ExceptionHandler func(Exception)
type ExceptionStruct struct {
catch ExceptionHandler
finally func()
try func()
}
//抛异常
func Throw(code int, message string, param ...interface{}) {
if param != nil {
hlog.NewStdLog().Error("code:%d,\nmessage: %s,\nerr:%v", code, message, param)
}
panic(Exception{Code: code, Message: message})
}
//尝试
func Try(handler func()) *ExceptionStruct {
return &ExceptionStruct{
try: handler,
}
}
//捕获异常方法设置
func (ex *ExceptionStruct) Catch(catch func(Exception)) *ExceptionStruct {
ex.catch = catch
return ex
}
//最终都要执行的方法
func (ex *ExceptionStruct) Finally(finally func()) *ExceptionStruct {
ex.finally = finally
return ex
}
//这里总体执行
func (ex *ExceptionStruct) Exc() {
defer func() {
if e := recover(); nil != e {
exception := e.(Exception)
catch := ex.catch
if catch != nil {
catch(exception)
}
}
finally := ex.finally
if finally != nil {
finally()
}
}()
ex.try()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。