How to get the stack trace pointing to actual error reason

前端 未结 8 1715
夕颜
夕颜 2020-12-18 19:42

Let\'s say I have some code like this:

value, err := some3rdpartylib.DoSomething()
if err != nil {
    panic(err)
}

In case err != ni

8条回答
  •  抹茶落季
    2020-12-18 19:54

    Shortly: this is not possible. Since errors are values, they are not treated in any special way. Due to this, when function (normally) returns, stack is no more available (ie. another function call may overwrite memory used by returning-error function' stack).

    There is a tool called trace which was introduced with go1.5, but for now, there is no comprehensive tutorial available neither any of those I found says that this kind of feature will be included.

提交回复
热议问题