[英]Powershell unexpected behavior of uncaught exception inside a catch block
以下powershell脚本产生非常异常的输出:
try {
throw "some exception"
echo "check point"
}
catch
{
echo "catch"
throw "some other exception"
exit(-1)
}
echo "finish"
输出:
catch
finish
除了脚本因未捕获的异常而退出时,我会throw "some exception"
并且脚本无法finish
。
即使将Powershell设置为在未捕获的异常之后继续运行,我也希望它执行exit(-1)
并且永远不会到达finish
。
谁能解释这种行为?
exit(-1)
无法访问,因为前一行throw "some other exception"
,并抛出了一个绕过块其余部分的异常。
我看到在两种情况下达到了“完成”状态:
$ErrorActionPreference
设置为"SilentlyContinue"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.