Skip to content

The ParseError "The Try statement is missing its Catch or Finally block" works only one way. #25491

@iRon7

Description

@iRon7

A ParseError is generated if "The Try statement is missing its Catch or Finally block" works only one way." but not vice versa: if "The Catch or Finally statement is missing its Try block".

See also: PowerShell/PSScriptAnalyzer#2098

Expected behavior

A simular behavior for both situations, meaning:
An error when invokeing the following script:

Invoke-ScriptAnalyzer -ScriptDefinition {function Test { Catch { write-verbose 'Test' } }}.ToString()

Or visa verse (no errors at alll), knowing that a standalone Try (e.g.: $a = try { 1 / $b }) makes more sense than a standalone Catch.

Actual behavior

Different behavior on the symmetrical situation.

Environment data

Version 7.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-Languageparser, language semantics

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions