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?
Not sure I really get your question, but it seems like all you want to do is to:
throw "message for the exception"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With