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

5 years, 8 months ago.

  • Author
  • #4374

    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}





    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

    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.