17.8. Summary

Errors in Windows PowerShell are stored in the $Error variable. The default size is 256 errors. You can increase the size of $Error if desired.

Errors can be described as terminating errors and nonterminating errors. The distinction is not clear-cut.

The $ErrorActionPreference variable allows you to specify a global preference for PowerShell behavior when an error occurs.

The $Error View variable allows you to specify two views of error information.

Two of the common parameters are relevant to errors:

  • The -errorAction paramter overrides for an individual cmdlet the value in $ErrorActionPreference.

  • The -errorVariable parameter allows you to store error information in a variable other than $Error.

The write-error cmdlet allows you to create custom error messages.

Get Professional Windows® PowerShell 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.