相关疑难解决方法(0)

PowerShell:创建自定义异常

这是我的代码:

Function Foo {
    If (1 -Eq 2) {
        # Do stuff
    }
    Else {
        # Throw custom exception
    }
}

Try {
    Foo

    Write-Host "Success"
}
Catch {
    $ErrorMessage = $_.Exception.InnerException.Message

    Write-Host "Failure"

    # Do stuff with the error message
}
Run Code Online (Sandbox Code Playgroud)

我想替换# Throw custom exception会导致Catch触发的代码.我怎样才能做到这一点?

.net powershell

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

powershell ×1