Error Handling

Errors are used to communicate unexpected conditions, an exceptional circumstance. Errors often contain useful information that can be used to diagnose a condition.

Handling errors is a critical part of working with the language, not least because PowerShell defines two different types of errors and several different ways to raise them.

As well as presenting different types of error, PowerShell has a number of different ways to handle errors, from ignoring errors to graceful handling.

During the course of this chapter, self-contained blocks of code are described as scripts. The terms function, script block, and script can be considered interchangeable in the context of error handling.

The following topics are covered in this ...

Get Mastering Windows PowerShell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.