As you write PowerShell scripts, it is important that you include error handling. Most of the time, this involves the use of Try/Catch statements. The tricky thing with Try/Catch is that you can only catch a terminating exception. There are a few cmdlets that by design will throw a terminating exception. But you have no…
Tag: ErrorHandling
Try and Catch Me If You Can
In looking at entries in this year’s Scripting Games, as well as posts I see in PowerShell forums, I thought I’d post a short guide to properly using Try/Catch. This is the way I think it should be used. Let’s start with a Try/Catch block that might look ok. Try { Get-Service Foo } Catch…