Some questions about Catch

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 4 years, 5 months ago.

  • Author
    Posts
  • #4374

    Kitt Holland
    Participant

    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

    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.