Skip to content

Rule request: The Catch (or Finally) statement is missing its Try block. #2098

Open
@iRon7

Description

@iRon7

There is a rule for The Try statement is missing its Catch or Finally block.:

Invoke-ScriptAnalyzer -ScriptDefinition {function Test { Try { write-verbose 'Test' } }}.ToString()
ParserError:
Line |
   1 |  … criptDefinition {function Test { Try { write-verbose 'Test' } }}.ToSt …
     |                                                                 ~
     | The Try statement is missing its Catch or Finally block.

But there is no rule for the opposite: a Catch (or Finally) statement that is missing its Try block:

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

Even it produces a syntax error during run time (as it assumes it is a cmdlet, which is definitely not a recommend function name):

Catch { write-verbose'Test' }
Catch: The term 'Catch' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions