.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
。谢谢