gpt4 book ai didi

exception - Powershell 捕获异常

转载 作者:行者123 更新时间:2023-12-03 00:24:34 24 4
gpt4 key购买 nike

我正在尝试这个来捕获异常,但它只是不起作用,而只是在脚本编辑器中显示错误我正在运行脚本: -

我在脚本 "\server\abc"中提到的路径并不真正存在,因此它应该将其作为异常捕获,而事实并非如此。帮助 帮助

Try
{

Get-ChildItem -Path "\\server\abc"

}
Catch
{

Write-Host "error"

}

最佳答案

您需要将 erroraction 设置为 STOP 才能终止错误 - 只有终止错误才会引发到 catch block 。

Try
{

Get-ChildItem -Path "\\server\abc" -ErrorAction Stop

}
Catch
{

Write-Host "error"

}

关于exception - Powershell 捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17347343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com