golang函数错误处理调用栈递归打印
2019-03-21 本文已影响0人
funcx
package errh
import (
"dog/util/log"
"runtime"
)
func Dao(err error) error {
if err != nil {
for i := 1; ; i++ {
pc, file, line, ok := runtime.Caller(i)
if !ok {
break
}
f := runtime.FuncForPC(pc)
if f.Name() != "runtime.main" && f.Name() != "runtime.goexit" {
log.Error.Println("file:", file, "line:", line, "funcName:", f.Name(), "error:", err.Error())
}
}
}
return err
}