Monday, July 23, 2012

Generating Terminating and non-Terminating Errors

Maybe you know that PowerShell has two kinds of errors: terminating and non-terminating.   The question is how to generate these in a script.  Write-Error generates a non-terminating error, but throw generates a terminating error.  Of course, one can specify the -erroraction to override.


More on errors: 
There are often several non-terminating errors if one runs get-childitem c:\windows, because wherever one does not have access, an error appears, but the "getting" continues.  The terminating error brings execution to a halt, so  get-childitem c:\windows -erroraction stop would end all further code execution  at the first "access denied" (unless Trap or Try/Catch is used).

No comments:

Post a Comment