Skip to content

Throw outside Try\Trap acts like a non-terminating error #19500

@dronkoff

Description

@dronkoff

Prerequisites

Steps to reproduce

Considering that Throw is designed for generate Terminating errors and -ErrorAction and $ErrorActionPreference for Non-Terminating errors, why the following code does not terminate at 5?

$ErrorActionPreference = "SilentlyContinue"
    1..10 | 
    ForEach-Object { 
        $_ 
        if($_ -eq 5) {
            throw "abc"
        } 
    }
$ErrorActionPreference = "Continue"
function Throw-Example
{
    [CmdletBinding()]
    param()
    "Line before the terminating error"
    Throw "This is my custom terminating error"
    "Line after the throw" 
}
Throw-Example -ErrorAction SilentlyContinue

Expected behavior

Throw terminates the execution regardless of -ErrorAction or $ErrorActionPreference, like it does with the default Continue value.

Actual behavior

Throw does not terminates the execution like a non-terminating error when -ErrorAction or $ErrorActionPreference value is SilentlyContinue.

Error details

No response

Environment data

# $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions