1 Star 0 Fork 0

纸喵软件 / gutils

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
runtime.go 598 Bytes
Copy Edit Raw Blame History
倒霉狐狸 authored 2020-08-26 22:41 +08:00 . 调整结构,升级rsa加密
/*
* 纸喵软件
* Copyright (c) 2017~2020 http://zhimiao.org All rights reserved.
* Author: 倒霉狐狸 <mail@xiaoliu.org>
* Date: 2020/3/3 下午4:26
*/
package gutils
import (
"fmt"
"runtime"
)
// PanicToError Panic转换为error
func PanicToError(f func()) (err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf(PanicTrace(e))
}
}()
f()
return
}
// PanicTrace panic调用链跟踪
func PanicTrace(err interface{}) string {
stackBuf := make([]byte, 4096)
n := runtime.Stack(stackBuf, false)
return fmt.Sprintf("panic: %v %s", err, stackBuf[:n])
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhimiao/gutils.git
git@gitee.com:zhimiao/gutils.git
zhimiao
gutils
gutils
82b352082121

Search