这是我的代码:
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
。我怎么能这样做?
答案 0 :(得分:19)
不确定我是否真的得到了你的问题,但似乎你想做的就是:
throw "message for the exception"