You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
371 B
21 lines
371 B
package util
|
|
|
|
//带有panic恢复的方法
|
|
func RunWithRecovery(f func()) {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
//TODO 全局日志记录
|
|
//LOGGER.Error("异步任务错误: %v", err)
|
|
}
|
|
}()
|
|
|
|
//执行函数
|
|
f()
|
|
}
|
|
|
|
//处理错误的统一方法 可以省去if err!=nil 这段代码
|
|
func PanicError(err error) {
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|