Summary
We started this chapter by looking at what an error actually is and covered some computer science that is applicable to most programming languages. We saw how PowerShell is different from many languages by having the concept of terminating and non-terminating errors, and how this is a feature of it being an interpreted language that sits on top of .NET.
Once we understood what errors are, we looked at different ways in which PowerShell can handle those errors using the $ErrorActionPreference
variable and the-ErrorAction
parameter.
We saw how we must turn errors into terminating errors so that we can use the most common way of trapping errors, the Try
/Catch
/Finally
family of statements. We also learned how we can use those statements to provide custom error-handling routines.
Having seen how we work with errors, we learned how we can use a Throw
statement to generate our own terminating errors when we encounter situations that are undesirable but don’t naturally...