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

This topic contains 3 replies, has 2 voices, and was last updated by  Don Jones 2 years, 8 months ago.

  • Author
    Posts
  • #23615

    GS
    Participant

    Hello,

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

  • #23618

    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

    GS
    Participant

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

  • #23621

    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.