Skip to content

Navid's Blog

Ideas, Experiments, and Lessons Learned

Menu
Menu

Why I Stopped Using Try-Catch Everywhere in My Backend Code

Posted on March 19, 2026 by Navid

For years, I wrapped everything in try-catch blocks. Every function, every API call, every database query. I thought that’s what defensive programming looked like.

I was wrong.

The Problem with Catching Everything

When you catch exceptions at every level, you lose context. You mask real errors. You make debugging a nightmare because you never know where things actually broke.

I spent hours tracing bugs only to find that someone had caught an exception, logged something vague like “error occurred”, and moved on.

What Changed My Mind

After a particularly nasty production incident where a database connection failure was swallowed somewhere deep in the call stack, I started being more intentional about error handling.

Now I follow three simple rules:

  • Let exceptions propagate from lower layers
  • Catch only at boundaries – API endpoints, message handlers, background jobs
  • Always log with context – include request IDs, user IDs, anything that helps debug

The Result

My code became easier to debug. Errors bubble up with full stack traces. I know exactly where things fail. And surprisingly, my code is shorter now.

Not every error needs to be caught immediately. Sometimes the best thing you can do is let it fail loudly so you can fix it properly.

Categories

  • AI Experiments
  • Coding
  • Debugging Stories
  • Hot Takes
  • Ideas
  • Lessons Learned
  • Project Management
  • Uncategorized
  • Vibe Coding

Recent Posts

  • Why I Stopped Using Microservices for Small Projects
  • I Gave AI Full Access to Our Production Database. Here’s What Happened
  • 5 API Design Mistakes I Learned the Hard Way
  • 5 API Design Mistakes I Learned the Hard Way
  • My Team Spent 2 Weeks Replacing Our Authentication — Here’s What Happened