我可以在 PowerShell 中获得详细的异常堆栈跟踪吗? [英] Can I get detailed exception stacktrace in PowerShell?

查看:21
本文介绍了我可以在 PowerShell 中获得详细的异常堆栈跟踪吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行这样的脚本:

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

我明白了

test
At C:	est.ps1:8 char:10

我可以获得详细的堆栈跟踪吗?

Can I get a detailed stack trace instead?

At bar() in C:	est.ps1:8
At foo() in C:	est.ps1:3 
At C:	est.ps1:11

推荐答案

有自动变量 $StackTrace 但它似乎更具体到内部 PS 细节而不是实际关心你的脚本,所以这不会有太大帮助.

There is the automatic variable $StackTrace but it seems to be a little more specific to internal PS details than actually caring about your script, so that won't be of much help.

还有 Get-PSCallStack 但不幸的是,一旦您遇到异常,它就会消失.但是,您可以在脚本中的每次抛出之前放置一个 Get-PSCallStack.这样您就可以在遇到异常之前立即获得堆栈跟踪.

There is also Get-PSCallStack but that's gone as soon as you hit the exception, unfortunately. You could, however, put a Get-PSCallStack before every throw in your script. That way you get a stack trace immediately before hitting an exception.

我认为可以通过使用 Powershell 的调试和跟踪功能编写此类功能的脚本,但我怀疑这是否容易.

I think one could script such functionality by using the debugging and tracing features of Powershell but I doubt it'd be easy.

这篇关于我可以在 PowerShell 中获得详细的异常堆栈跟踪吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆