DEV Community

Discussion on: The Secret Life of JavaScript: The Catch

Collapse
 
trinhcuong-ast profile image
Kai Alder

The "let errors happen and catch them high up" approach is something I wish I'd internalized sooner. Early in my career I was wrapping literally everything in try/catch and returning null or default values all over the place. Code looked "safe" but it was lying — silently swallowing errors and producing bad state downstream.

One pattern I've found helpful is creating a thin error boundary layer at route/controller level that logs + maps errors to user-friendly responses, and then letting everything underneath just throw freely. Way cleaner than scattering catch blocks everywhere.

The narrative format works well for this topic btw. Stack unwinding is one of those things that's hard to visualize from docs alone — the "tearing down boxes" metaphor makes it click.

Collapse
 
aaron_rose_0787cc8b4775a0 profile image
Aaron Rose

💡💯🙏

Collapse
 
aaron_rose_0787cc8b4775a0 profile image
Aaron Rose

Kai, you're spot on. "Silently swallowing errors" is exactly the trap so many of us fall into early on. Your pattern of a thin error boundary at the route/controller level is the perfect real-world implementation of this philosophy. Thanks for adding such great senior-level context! cheers! 💯✨