O'Reilly logo

Learn Windows PowerShell in a Month of Lunches by Don Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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” ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required