"catch clauses should do more than rethrow" should consider "when" clause (csharp/RSPEC-2737)

Using: SonarLint for Visual Studio 2019 v. 4.37

If I have

try
{
    some code;
}
catch (Exception e)
{
    if (some condition)
        throw;
}

it doesn’t complain, but if I move the condition in the when clause:

try
{
    some code;
}
catch (Exception e) when (some condition)
{
    throw;
}

then it does complain with Rules explorer

If having a condition in the catch body before the rethrow is sufficient to avoid RSPEC-2737, having the same condition in the when clause should probably have the same effect.

Hi Maxime

Welcome to the community :slight_smile:

In your first example the exception is always caught and only rethrown under a specific condition satisfying RSPEC-2737
In your second example the exception is only caught under a specific condition and always rethrown (without any additional logic) breaking the rule.

This looks correct to me, but please let me know if I’m missing something?

Thanks

Tom