SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
755 stars 223 forks source link

Fix S1854 FP: Throw should visit finally #9466

Open pavel-mikula-sonarsource opened 1 week ago

pavel-mikula-sonarsource commented 1 week ago

We need to add a branch for Throw semantics to connect the blocks

    public int ReadInFinallyAfterCatch()
    {
        var value = 0;
        try
        {
            CanThrow();
            value = 42;
        }
        catch
        {
            value = 1;  // Noncompliant FP, used in finally after the throw
            throw;
        }
        finally
        {
            Log(value);
        }
        return value;
    }