Skip to content

.WasThrownFromThrowStatement not available for System.Exception #6288

Closed

Description

@alx9r

Steps to reproduce

try
{
    throw
}
catch
{
    [bool]$_.Exception.WasThrownFromThrowStatement
}

try
{
    throw [System.Exception]::new()
}
catch
{
    [bool]$_.Exception.WasThrownFromThrowStatement
}

Expected behavior

True
True

Actual behavior

True
False

Environment data

> $PSVersionTable

Name                           Value                                            
----                           -----                                            
PSVersion                      6.0.0                                            
PSEdition                      Core                                             
GitCommitId                    v6.0.0                                           
OS                             Microsoft Windows 6.3.9600                       
Platform                       Win32NT                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                          
PSRemotingProtocolVersion      2.3                                              
SerializationVersion           1.1.0.1                                          
WSManStackVersion              3.0                                              

Activity

  1. mklement0 commented on Mar 1, 2018

    @mklement0
    Contributor

    As discussed, the problem happens with [System.Exception]-derived types as well, except for [System.Management.Automation.RuntimeException], which is what PowerShell implicitly uses when you throw nothing or any object that is not an exception.

  2. added
    WG-Languageparser, language semantics
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Mar 2, 2018
  3. BrucePay commented on Mar 14, 2018

    @BrucePay
    Collaborator

    The .WasThrownFromThrowStatement property along with RuntimeException are implementation details for the PowerShell runtime and aren't intended to be used by end users. .WasThrownFromThrowStatement exists so that the throw statement can throw an exception that won't be caught by pipeline exception handlers allowing the exception to propagate up through a set of nested pipelines. Since it's PowerShell-specific, it won't appear on any non-PowerShell types.

  4. alx9r commented on Mar 14, 2018

    @alx9r
    Author

    Since it's PowerShell-specific, it won't appear on any non-PowerShell types.

    Thanks for the clarity Bruce Payette (@BrucePay)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.WG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions