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

Welcome Forums General PowerShell Q&A What am I doing wrong in try{}catch{} statement?

This topic contains 3 replies, has 2 voices, and was last updated by

 
Keymaster
3 years, 7 months ago.

  • Author
    Posts
  • #23615
    GS

    Participant
    Points: 0
    Rank: Member

    Hello,

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

  • #23618

    Keymaster
    Points: 2
    Rank: Member

    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
    Points: 0
    Rank: Member

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

  • #23621

    Keymaster
    Points: 2
    Rank: Member

    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.

The topic ‘What am I doing wrong in try{}catch{} statement?’ is closed to new replies.