PowerShell defines two different types of errors: terminating and non-terminating errors.
A terminating error stops a pipeline processing; once an error is thrown, everything stops. A terminating error might appear as the result of using throw
. In the following function, the second Write-Host
statement will never execute:
PS> function ThrowError { Write-Host 'First' throw 'Error' Write-Host 'Second' } PS>ThrowError First Error At line:3 char:5 + throw 'Error' + ~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (Error:String) [], RuntimeException + FullyQualifiedErrorId : Error
Terminating errors are typically used to convey that something unexpected and terminal has occurred, a catastrophic failure that prevents a script continuing.