A catch clause only rethrows what it caught

tx0/csharp:useless-catchrecommendedwarningreliability/error-handlingdepth fastsmell

What it finds

catch (Exception) { throw; } as the only handler catches and rethrows, which changes nothing and makes the code harder to read. Clauses followed by broader ones, where the rethrow keeps an exception away from the later handler, are left alone, and so are clauses with a filter.

From the rule's source, useless_catch.rs.

Example from the rule's tests
using System; class Pass{    void Run()    {        try        {            Work();        }        catch (Exception)tx0 reports: this catch only rethrows the exception        {            throw;        }        try        {            Work();        }        catch (ArgumentException)        {            throw;        }        catch (Exception e)        {            Console.WriteLine(e);        }    }     void Work() { }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:useless-catch" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:useless-catch] reason="..."

tx0 explain tx0/csharp:useless-catch shows the same in the terminal. Found a false positive? Report it.