小编Vla*_*rov的帖子

Powershell 脚本在 try/catch 块中捕获异常时停止;$ErrorActionPreference

问题:powershell 脚本因使用 $ErrorActionPreference 时应该由 try 块捕获的异常而停止

例子:

$ErrorActionPreference = 'Stop'
try {
    ThisCommandWillThrowAnException
} catch {
    Write-Error 'Caught an Exception'
}
# this line is not executed. 
Write-Output 'Continuing execution'  
Run Code Online (Sandbox Code Playgroud)

powershell

5
推荐指数
1
解决办法
3948
查看次数

标签 统计

powershell ×1