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 chapter:
- Error types
- Error actions
- Raising errors
- Catching errors