10

Error Handling – Oh No! It’s Gone Wrong!

There are, broadly, two types of problems that we encounter when using PowerShell: problems that our code encounters and problems with our code. The first type may be as simple as a FileNotFound message in response to Get-ChildItem. The second type can be much harder to understand, as it may involve problems related to scope, which we saw in Chapter 9, Don’t Repeat Yourself – Functions and Scriptblocks, or an unexpected divide by zero error. We’ll deal with problems that our code encounters in the first half of this chapter, and then move on to problems we may find in our code in the second half.

We’ll start by defining what an error is and look at the two types of errors our code will encounter: terminating ...

Get PowerShell 7 Workshop 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.