How to Use Try/Catch/Finally for Non-Terminating Errors


Summary: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell and Try/Catch/Finally for non-terminating errors.

Microsoft Scripting Guy, Ed Wilson, is here. Today I want to present a video about using Windows PowerShell Try/Catch/Finally with non-terminating errors—that is, Windows PowerShell can progress past the errors when they occur to the next line of code.

Note  For more information, refer to Understanding Non-Terminating Errors in PowerShell.

Here is the video: 

[View:https://youtu.be/xhV2EVjivr4:550:0]

Here is a link to the video from YouTube if you would like to download it or play it offline in a different video player:  Non-terminating Errors in Windows PowerShell by Ed Wilson.

Join me tomorrow for International Talk Like a Pirate day.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

Comments (3)

  1. Steve says:

    Wow… thanks for this! I got around the issue by constantly checking if $error was not $null after to see if there was a problem. This makes it easier.

  2. Ed Wilson says:

    @Steve Cool. I am glad that it helped you. Thank you, this makes my day.

  3. Joe King says:

    Find that interesting and helpful.
    Would I use Try Catch Finally with a variable assignment such as:
    $zBefore = (get-process -name Excel).Id
    (Getting process Ids of running Excel programs – what if there are no Excel running?)
    Eg
    try{$zBefore = (get-process -name Excel).Id -ErrorAction ‘Stop’}

    (I can’t seem to get the syntax correct, so I am beginning to think I am up the wrong tree!)

    I am learning Powershell but have done much procedural programming in the past.

Skip to main content