是否可以获取从调用范围返回函数的行号?
例:
func callee() error {
if cond {
return errors.New("whoops!")
}
return nil
}
func caller() {
// Possible to retrieve the line number of callee return here?
callee()
}
Run Code Online (Sandbox Code Playgroud)
我认为这是不可能的,因为它应该已经从堆栈中删除,但也许它仍然在某处缓存?
用例是我有一个HTTP处理程序,我想记录返回错误的行和文件名,而不必乱丢代码.
go ×1