这是我的代码:
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
触发的代码替换。我怎样才能做到这一点?