Skip to content

A catch block in a try / catch statement qualified with type System.Management.Automation.RuntimeException traps *any* exception #16392

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

In practice, catch [System.Management.Automation.RuntimeException] { ... } seems to behave the same as an unqualified catch block.

That is, it catches any exception - even those not derived from System.Management.Automation.RuntimeException

try { throw ([System.ArgumentException] 'foo') }
catch [System.Management.Automation.RuntimeException] { 'What are you doing here? ' }

Expected behavior

The exception thrown should surface as a script-terminating error, because its type isn't derived from System.Management.Automation.RuntimeException, so the catch block should not be entered.

Actual behavior

'What are you doing here?' is output, because the catch block was unexpectedly entered.

Error details

No response

Environment data

PowerShell Core 7.2.0-rc.1

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions