What am I doing wrong in try{}catch{} statement?

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 8 months ago.

  • Author
    Posts
  • #23615
    Profile photo of GS
    GS
    Participant

    Hello,

    I can not figure out why Exception on connection never being caught in "catch" statement. See below.

  • #23618
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Read "The Big Book of PowerShell Error Handling." You're not specifying an -ErrorAction, so there's no exception to be caught.

  • #23619
    Profile photo of GS
    GS
    Participant

    I thought by default all errors will be caught in try{} catch{} statement unless you choose to alter default behavior.

  • #23621
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Well, no. Not exactly. This is all in the free book, but briefly, a command can generate terminating exceptions or non-terminating errors. You can't catch non-terminating. It's up to the command author which is produced by default, but the general rule is non-terminating for most operations.

You must be logged in to reply to this topic.