Empty Catch Block in C#: Why It Fails You and How to Fix It (video)
Learn why empty catch blocks in C# hide production failures, see before-and-after examples with logging and rethrow patterns, and catch them automatically with static analysis.
Transcript
Empty Catch Block in C#: Why It Fails You and How to Fix It. Here's the short version.
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.
What counts as an empty catch block?. In C#, an empty catch is any catch clause whose body does nothing meaningful. Variations that are equally dangerous include catch blocks that only contain a comment.
Here's the problem in code: failure is swallowed.
And here's the fix: observable failure with targeted handling.
Why empty catches are a production risk. 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.
Want to find these issues in your own code? Connect your GitHub repository to CodeInspector. You'll get findings with the file, line, severity, and a recommended fix, plus HTML and PDF reports for your team. Start free at codeinspector.app.
More videos
- CodeInspector product demo (0:54)
- CodeInspector Now Works Inside Claude: Scan and Fix Code in One Conversation (video) (1:20)
- throw vs throw ex in C#: Why throw ex Destroys Your Stack Trace (video) (1:22)
- Thread.Sleep vs Task.Delay in C#: Which to Use and Why (video) (1:38)
- Task.Result and .Wait() Deadlocks in C#: Why Sync-over-Async Hangs (video) (1:47)
- ILogger Best Practices in .NET: Structured Logging That Helps You Debug (video) (1:20)