这是我的代码:
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 custom exception
触发的代码替换Catch
。我怎样才能做到这一点?
最佳答案
不确定我是否真的收到您的问题,但是似乎您想要做的只是:
throw "message for the exception"
关于.net - PowerShell:创建自定义异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11703180/