1 Star 0 Fork 1

周涛/go_utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
exception.go 654 Bytes
一键复制 编辑 原始数据 按行查看 历史
step 提交于 2020-07-23 14:48 . 归档常用的附件库
package exception
import (
"fmt"
"github.com/davyxu/cellnet"
"reflect"
"runtime/debug"
)
func defaultCallback(raw interface{}, queue cellnet.EventQueue) {
fmt.Println(fmt.Sprintf("%v\n%s", raw, string(debug.Stack())))
queue.StopLoop()
}
func SetCapturePanic(queue cellnet.EventQueue, callback func(raw interface{}, queue cellnet.EventQueue)) {
// 通过反射修改队列中异常捕获函数
queueValue := reflect.ValueOf(queue)
if callback == nil {
callback = defaultCallback
}
queueValue.MethodByName("SetCapturePanicNotify").
Call([]reflect.Value{reflect.ValueOf(callback)})
// 开启异常捕获
queue.EnableCapturePanic(true)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/super_step/go_utils.git
git@gitee.com:super_step/go_utils.git
super_step
go_utils
go_utils
v1.1.5

搜索帮助