PSScriptAnalyzer
PSScriptAnalyzer copied to clipboard
Add a rule to alert `catch [RuntimeException] { ... }`
Summary of the new feature
In practice, catch [System.Management.Automation.RuntimeException] { ... } behaves the same as an unqualified catch block. That is, it catches any exception. See details in https://github.com/PowerShell/PowerShell/issues/16392.
Reason for that is explained in https://github.com/PowerShell/PowerShell/issues/16392#issuecomment-966712592.
Proposed technical implementation details (optional)
It would be nice to have a rule to caution against using RuntimeException as the type for a catch clause.
What is the latest version of PSScriptAnalyzer at the point of writing
1.20.0
Interesting. I did a search on GitHub and it seems there is no public usage of that, therefore I am not sure if just documenting this edge case is good enough. Marking as up for grabs. https://github.com/search?q=catch+%5BRuntimeException%5D&type=code
@bergmeister The old GitHub code search isn't very good. When I tried their new "dedicated" code search I see at least some of public usage: https://cs.github.com/?scopeName=All+repos&scope=&q=catch%20%5BSystem.Management.Automation.RuntimeException%5D