Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: Creating a Custom Exception

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?

like image 959
Nick Avatar asked Jul 28 '12 17:07

Nick


1 Answers

Not sure I really get your question, but it seems like all you want to do is to:

throw "message for the exception"
like image 62
manojlds Avatar answered Oct 02 '22 20:10

manojlds