Here is my code:
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
}
I'd like to replace # Throw custom exception
with code that will cause the Catch
to fire. How can I do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…