Add Error Handling to Scripts

When you get to the point where you are creating scripts and modules that you wish to reuse or share within your organization or publicly, you will want to put a lot of thought into how you will handle errors.

In some cases, you will want to generate and “throw” an error back to the user, perhaps due to invalid user input or some other condition that requires the caller's attention before continuing. In other cases, you will need to “trap” or “catch” an error and perform some processing to address the error or otherwise append some information to the error and throw it back to the user. And in still some other cases, your error handling will be in the form of basic cleanup of objects to prevent performance degradation. ...

Get Automating Microsoft® SharePoint® 2010 Administration with Windows PowerShell® 2.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.