为Biztalk部署创建PowerShell脚本。我编写了一个普通的try catch块来处理部署期间的异常。我的代码能够捕获像
这样的例外 #File not Found
#语法错误
但像Dependency applications needs to be installed before installing
这样的例外 - 并没有被抓住。但当我检查Powershell控制台时,我可以看到..
CommandExecuted with 1 Error
。
请建议如何处理这些例外情况。
答案 0 :(得分:2)
除了非终止错误之外,您应该知道PowerShell try / catch不会“捕获”可执行文件返回错误退出代码的事实。您可以使它生成如下异常:
some.exe someargs
if ($LastExitCode -ne 0) { throw "some.exe failed with exit code $LastExitCode" }