Skip to main content
ai-slop/csharp-empty-catch-rethrowmanual fix

Catch that only rethrows.

`catch (...) { throw; }`: a handler whose only statement rethrows. It changes nothing and adds a try block to read.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

csharp-empty-catch-rethrow.cs
✗ Flagged
try
{
    await _storage.UploadAsync(blob);
}
catch (IOException)
{
    throw;
}
Why this trips

Deterministic window match: flags a `catch` whose body, read across the next five lines, is exactly `throw;`.

csharp-empty-catch-rethrow.cs
✓ Clean
try
{
    await _storage.UploadAsync(blob);
}
catch (IOException ex)
{
    throw new UploadFailedException($"Upload of {blob.Name} failed", ex);
}
What changed

Delete the try/catch. Use `finally` for cleanup, or `throw new SomeException("context", ex)` when you need to add context.

Agents wrap calls in try/catch by reflex, then find they have nothing to do with the error and rethrow it. The scaffolding stays.

How this rule is justified.

Rule id

ai-slop/csharp-empty-catch-rethrow

Enforcing engine

ai-slop

Detector strategy

Deterministic window match: flags a `catch` whose body, read across the next five lines, is exactly `throw;`.

Legitimate code that is NOT flagged

Catches that log, clean up, or wrap the exception (`throw new X(..., ex)`) before rethrowing are not flagged.

Evidence

Part of aislop's C# rule set. First-class C# support, including C#-specific AI-slop rules, arrived in aislop v0.14.1.