Skip to content

Missing try{} block not reported as a problem #1700

Open
@bytepl

Description

@bytepl

Steps to reproduce

Write-Output "Test"
catch {
    Continue
}

save it as a file, then run Invoke-ScriptAnalyzer against it.

Expected behavior

An error should be displayed, saying that there's no 'try' block, just 'catch'.

Actual behavior

No error is returned and the script throws an error when executed.

catch : The term 'catch' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a p
 again.
At C:\Users\mchojnac\Desktop\test.ps1:2 char:1
+ catch {
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (catch:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1023
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1023
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions