Some questions about Catch

Welcome Forums General PowerShell Q&A Some questions about Catch

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
5 years, 8 months ago.

  • Author
    Posts
  • #4374

    Participant
    Points: 0
    Rank: Member

    Hey Guys, trying to properly implement Try Catch in a script I'm working on.

    I've used Catch before, but never to catch a specific error.

    From what I understand it should look like:

    Try {Do-Thing}

    Catch

    {[ErrorType]

    DoOther-Thing

    }

    Right now I am trying to create an error for parameter violation error, what do I need to put in the [ErrorType] to get it to recognize that error? I tried ParameterBindingValidationException but that didn't work.

  • #4378

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    No, it's more Try { Do-Thing } Catch [exception] { Whatever } Catch { Whatever }

    The [exception] is a class type. There's a good example in about_try_catch_finally. You almost have to cause the error once, grab the exception, and then look at it. Or, look up the exception class in MSDN.

The topic ‘Some questions about Catch’ is closed to new replies.