6
這裏是我的代碼:的PowerShell:創建一個自定義異常
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
}
我想要的代碼,將導致Catch
火更換# Throw custom exception
。我怎樣才能做到這一點?
我用'$ =的ErrorMessage $ _ Exception.InnerException.Message'因爲我認爲。將與'Throw'一起工作。事實證明,在這種情況下它應該是'$ _。Exception.Message'。謝謝! – Nick 2012-07-29 02:53:16