Skip to main content

Anti-Pattern: Swallowed Exceptions (Silent Failures)

Description​

Catching an exception and doing nothing (empty catch block). This hides bugs, making them impossible to diagnose because there is no log entry or stack trace.

Impact​

  • Debugging: Developers fly blind. Critical failures (e.g., payment failure, database error) look like "success" or just silent stops.
  • Data Integrity: Processes might partially complete, leaving data in an inconsistent state.

Detection​

Look for catch (Exception) { } or catch { }.

// ❌ BAD: Just "hopes" it works. Hides critical null pointers or DB errors.
try {
ProcessPayment();
} catch (Exception) { }

Refactoring​

At minimum, Log the exception.

// ✅ GOOD: Logs the error so we know what happened.
try {
ProcessPayment();
} catch (Exception ex) {
Logger.Error("Payment failed", ex);
// Optionally rethrow if the caller can handle it
throw;
}
  • Log Then Throw: If you must catch to add context, log the inner exception and then throw; (or throw a wrapped custom exception).

2026 Audit Findings​

  • Occurrences: > 20 exact empty catches.
  • Severity: High (Hidden Bugs).
  • Key Locations:
    • Global.asax
    • ImportOMGTProcess.cs
    • ProspectController.cs