Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net PowerShell:创建自定义异常_.net_Powershell - Fatal编程技术网

.net PowerShell:创建自定义异常

.net PowerShell:创建自定义异常,.net,powershell,.net,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

这是我的密码:

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
}

我想将
#抛出自定义异常
替换为将导致
捕获
触发的代码。我该怎么做呢?

我不确定我是否真的明白你的问题,但你似乎只想:

throw "message for the exception"

我使用的是
$ErrorMessage=$\u.Exception.InnerException.Message
,因为我假设它可以与
Throw
一起使用。在这种情况下,它应该是
$\异常.Message
。谢谢