Chapter 22. Trapping and handling errors
Anytime you’re dealing with computers, errors are bound to occur: network problems, permission denied, server not found ... you know what I’m talking about. Fortunately, your PowerShell commands and scripts can plan for those errors and deal with them, rather than spewing out a bunch of red text.
22.1. Dealing with errors you just knew were going to happen
To be clear, I’m not talking about errors that you make, such as typos, using the wrong syntax, or something like that. Your errors are called bugs, and we’ll deal with those in the next chapter. This chapter is going to deal with the errors that are out of your control, but that you can usually anticipate. Here are some examples:
- A “file not found” ...
Get Learn Windows PowerShell in a Month of Lunches 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.