(ship int)
| 56 | } |
| 57 | |
| 58 | func getInfo(ship int) (infoStr string) { |
| 59 | |
| 60 | panicInfo := new(bytes.Buffer) |
| 61 | // It is also possible to not specify the end point layer as i := ship;; i++ and end the loop with if !ok, |
| 62 | // but it will keep going until the bottom layer error information is reached. |
| 63 | // (也可以不指定终点层数即i := ship;; i++ 通过if!ok 结束循环,但是会一直追到最底层报错信息) |
| 64 | for i := ship; i <= StackEnd; i++ { |
| 65 | pc, file, lineNo, ok := runtime.Caller(i) |
| 66 | if !ok { |
| 67 | break |
| 68 | } |
| 69 | funcname := runtime.FuncForPC(pc).Name() |
| 70 | filename := path.Base(file) |
| 71 | funcname = strings.Split(funcname, ".")[1] |
| 72 | fmt.Fprintf(panicInfo, "funcname:%s filename:%s LineNo:%d\n", funcname, filename, lineNo) |
| 73 | } |
| 74 | return panicInfo.String() |
| 75 | |
| 76 | } |
no test coverage detected