ds9567 2018-09-25 01:43
浏览 116

如何正确处理运行时错误.Caller(0)

I'm using runtime.Caller(0) to return the file name:

_, file, _, ok := runtime.Caller(0)
if !ok {
    // What should I do here?
}

I would like to know:

  • Why this function in specific doesn't provide an error?
  • What should I do if it fails? (Panic, fatal error?)
  • What could be wrong to fail? Should I validate at all?

This is my first week using Go, so I might seem like stupid questions if you are already advanced, and I'm sorry for that.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doute3621 2018-09-26 04:24
    关注

    Why this function in specific doesn't provide an error?

    That is opinion based.

    What should I do if it fails? (Panic, fatal error?)

    Whatever fits your needs.

    What could be wrong to fail?

    Everything. E.g. a binary stripped of debug information.

    Should I validate at all?

    Yes of course.

    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制