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
797 stars 229 forks source link

Fix S6667 FP: The catch block is going to rethrow, therefore no need to log the exception #9666

Closed ltvan closed 2 months ago

ltvan commented 2 months ago

Description

I tried to log some activities in case that a specific exception raised, and re-throw it. But the analyzer reports that S6667: Logging in a catch clause should pass the caught exception as a parameter.

If I put the exception as a parameter, S2139 will be triggered.

Repro steps

try
{
//...
}
catch (SomeException)
{
    _logger.LogError("Some logging...")
    throw;
}

Expected behavior

If the exception is going to be re-thrown, S6667 should not be triggered.

Actual behavior

S6667 is still triggered in the case that the exception is going to be re-thrown.

Known workarounds

N/A

Related information

sebastien-marichal commented 2 months ago

Hello @ltvan,

Thank you for reporting this issue. This has already been reported to us and confirmed as being an FP.

You can see the details in this community post.

Have a good day!