Can I get detailed exception stacktrace in PowerShell?

前端 未结 12 1124
暗喜
暗喜 2020-12-02 12:23

Runing such script:

 1: function foo()
 2: {
 3:    bar
 4: }
 5: 
 6: function bar()
 7: {
 8:     throw \"test\"
 9: }
10: 
11: foo

I see

12条回答
  •  遥遥无期
    2020-12-02 12:47

    You can not get a stack trace from exceptions of the PowerShell code of scripts, only from .NET objects. To do that, you will need to get the Exception object like one of these:

    $Error[0].Exception.StackTrace
    $Error[0].Exception.InnerException.StackTrace
    $Error[0].StackTrace
    

提交回复
热议问题