Error types
As mentioned above, PowerShell defines two different types of errors: terminating and non-terminating errors.
Each command in PowerShell may choose to raise either of these, depending on the operation.
Terminating errors
Terminating errors are used to stop a script in the event of a problem, or to stop an operation from continuing.
Terminating errors are split in two, depending on how the error is raised; this leads to some inconsistent behavior, which is explored in the Raising errors recipe later in this chapter.
A terminating error stops a script once an error is thrown. No further commands will execute after the error is thrown.
When running the following command, the second Write-Host statement will never execute:
function Stop-Command {
Write-Host 'First'
throw 'Error'
Write-Host 'Second'
}
Running the function will show that the second Write-Host command does not execute:
PS> $ErrorActionPreference...