【发布时间】:2017-03-08 20:28:32
【问题描述】:
如果尝试在 ineracvie powershell 中做某事,是否有可能捕获特定错误? 我的意思是:
powershell.exe
PS C:>_
PS C:>fuu
fuu: this is not a cmdlet .... BLA BLA BLA
+ ~~~
+ CategoryInfo : ObjectNotFound: (fuu:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
这是 ineractive powershell 的正常行为。 我可以在我的 Profile.ps1 中放一些东西,以便一切都保持这样,但对于特定错误,例如这些 CommandNotFoundException,只有在这些错误上我才改变 powershell 的行为?也许是一个新的 wirte-host 或其他东西。
powershell.exe
PS C:>_
PS C:>fuu
fuu: this is not a cmdlet so CommandNotFoundException and now i behave diffrent my lord
PS C:>_
所以是的,我知道 try catch 等等 -> 在 SCRIPTS 但我的意思是交互作为默认行为!
谢谢
[更新]
把事情弄清楚。真正的案例是代码设计。 ExecutionPolicy 是 AllSignt,如果我忘记签署测试代码当然会出现错误:
+ ~~~~~~~~~~~~~~
+ CategoryInfo : Sicherheitsfehler: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
但在这种情况下,我不想要这个错误,我想问一个问题,你想签名吗?是/否
....而不是那样做。
【问题讨论】:
标签: powershell error-handling try-catch interactive