Empty Catch Block in C#: Why It Fails You and How to Fix It
An empty catch block in C# compiles cleanly and still feels like “handling” an error — but it discards the exception, hides failures from operators, and makes production incidents nearly impossible to diagnose. This guide explains the risk, shows concrete before-and-after C# examples, and how static analysis tools such as CodeInspector flag the pattern across entire repositories.
What counts as an empty catch block?
In C#, an empty catch is any catch clause whose body does nothing meaningful: no logging, no recovery, no rethrow, and no documented justification. The compiler allows it, so the smell often survives code review unless reviewers know to look for it.
Variations that are equally dangerous include catch blocks that only contain a comment, or catch (Exception) handlers that swallow every failure type without recording context.
Why empty catches are a production risk
When an exception is swallowed, callers believe work succeeded. Payment retries stop, cache invalidation never runs, and downstream systems receive incomplete data — all while your metrics still look healthy.
Support teams then chase “it failed sometimes” reports without stack traces. The fix cost rises because the original failure context is gone.
- Silent data loss when persistence or messaging fails inside the catch
- Masked dependency outages (HTTP, database, queue) that should trigger alerts
- Tests that pass because exceptions never propagate to assertions
- Compliance and audit gaps when security-relevant errors are not logged
Before: typical empty catch in application code
This pattern often appears in integration glue code where a developer wanted to “keep the request moving”. It removes the only signal that the external call failed.
public async Task SyncCustomerAsync(Guid customerId, CancellationToken cancellationToken)
{
try
{
await _crmClient.PushCustomerAsync(customerId, cancellationToken);
}
catch (Exception)
{
// TODO: handle later
}
await _repository.MarkSyncedAsync(customerId, cancellationToken);
}
After: log, narrow the catch, and fail when you cannot recover
Prefer catching specific exception types, log structured context (customer id, correlation id), and either recover safely or rethrow so upstream code can abort the workflow.
If you must absorb an error, document why in the catch body and emit a metric or log at Warning/Error level — never leave the block empty.
public async Task SyncCustomerAsync(Guid customerId, CancellationToken cancellationToken)
{
try
{
await _crmClient.PushCustomerAsync(customerId, cancellationToken);
}
catch (HttpRequestException ex)
{
_logger.LogError(ex, "CRM sync failed for {CustomerId}", customerId);
throw;
}
catch (TaskCanceledException ex) when (cancellationToken.IsCancellationRequested)
{
_logger.LogWarning("CRM sync cancelled for {CustomerId}", customerId);
throw;
}
await _repository.MarkSyncedAsync(customerId, cancellationToken);
}
When is catching and ignoring acceptable?
Rarely. Acceptable cases are tightly scoped: expected control-flow (e.g. TryParse patterns without exceptions), well-documented fire-and-forget telemetry where loss is harmless, or cleanup paths where you log and continue because the primary operation already succeeded.
Even then, log at Debug or Information so operators can correlate behavior. “Empty except on purpose” should be obvious in review, not hidden behind a blank block.
Find empty catches with static code analysis
Manual review misses empty catches in large .NET solutions — especially in legacy folders nobody owns. Static analysis applies the same rule on every file every scan.
CodeInspector includes rules for empty catch blocks, missing logging on error paths, and related C# reliability patterns. Run a scan on your GitHub repository to get file-and-line findings you can triage before release.
- Scan public GitHub URLs from the dashboard or connect a private repo
- Review severity-ranked findings in the Explorer workspace
- Track regressions with scan history and share PDF summaries with your team
Next steps for your codebase
Search your solution for catch blocks with empty bodies, fix critical paths first (payments, auth, data writes), then enable automated scanning on main so new empty catches cannot slip in unnoticed.
Pair this article with our guides on C# code review and common C# code smells for a broader quality checklist.