Using Try/Catch/Finally with #PowerShell – #powertweet

By | May 3, 2013

Nugget time!

We all know that we can have multiple catch blocks when using a try/catch/finally, right?

Good.

When using try/catch/finally with PowerShell, don’t forget that when an error occurs, the jump to the catch fires, and the first matching catch block will be executed so getting the order of your catch blocks correct is important.

You need to ensure that the catch blocks are ordered from “specific” to “generic”. Look for specific errors first, less specific next, and so on all the way to your most generic.

Simples.

more to follow…

Leave a Reply

Your email address will not be published. Required fields are marked *