Skip to content

Latest commit

 

History

History

Not-true-terminating

ThrowTerminatingError produces not true terminating errors

Unlike throw or Write-Error -ErrorAction Stop, $PSCmdlet.ThrowTerminatingError produces not true terminating errors. They terminate the current command but they do not terminate callers unless they use try blocks or $ErrorActionPreference = 'Stop'.

help about_preference_variables says

$ErrorActionPreference

      Neither $ErrorActionPreference nor the ErrorAction common parameter
      affect how Windows PowerShell responds to terminating errors (those
      that stop cmdlet processing).

As far as tests show that $ErrorActionPreference affects how PowerShell responds to errors created by ThrowTerminatingError, it looks like this help confirms that ThrowTerminatingError is not true terminating.

Scripts