All rules

P009 SwallowedExceptions

Applies to
Pull requests, through the GitHub App
Severity
Warning (fails the check under fail-on-warnings)
Summary
A change catches an exception and does nothing with it.
Flags
Added code with an empty catch block (C#, Java, JS/TS and similar; comments inside count as empty), or a Python except block containing only pass. Up to four consecutive added lines. A catch inside a string literal is skipped. Generated files (<auto-generated in the first 10 lines) are skipped. Downgraded to Info by a comment "aibysitter-ignore P009: <reason>" (//, #, /* */ or <!-- -->) after code on the catch line or alone on the line above, with a reason of at least 10 characters; the finding shows the reason. A marker with no reason, a shorter one, or no ':' after P009 leaves the Warning and the summary says why.
Known limits
Removing the try/catch, or replacing it with a feature test that does not cover the throw, clears the finding without handling the exception.
A catch whose body only assigns a value (x = null;) is not flagged.
A justification's reason is not checked beyond its length.

Before

try { Save(order); }
catch (Exception) { }

After

try { Save(order); }
catch (DbUpdateException ex) { logger.LogError(ex, "Save failed"); throw; }

Fix