Error Handling
Errors communicate unexpected conditions and exceptional circumstances. Errors often contain useful information that can be used to diagnose a problem.
PowerShell has two different types of errors, terminating and non-terminating, and several different ways to raise and handle them.
Error handling in PowerShell is a complex topic, which is not helped by incorrect assertions in help documentation surrounding terminating errors. These challenges are explored in this chapter.
Self-contained blocks of code are described as scripts in this chapter. That is, functions, script blocks, and scripts can be considered interchangeable in the context of error handling.
This chapter covers the following topics:
- Error types
- Error actions
- Raising errors
- Catching errors
The two different types of error will be explored first.