Blog
Lessons from open-source: try..catch(_)?

Lessons from open-source: try..catch(_)?

This lesson is picked from Next.js source code. In this article, you will learn that you can use an underscore “_” to intentionally ignore error in your catch block.

Reasons why you want to ignore error parameter in your catch block:

  1. There’s no further processing required when an error is encountered.

  2. Implement a fallback that does not rely on error.

Learn the best practices used in open source

Where else is catch(_) used in Next.js source code?

This search result shows that catch(_) is used in quote some places across the nextjs source code.

About me:

Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

I am open to work on interesting projects. Send me an email at ramu.narasinga@gmail.com

My Github —  https://github.com/ramu-narasinga

My website —  https://ramunarasinga.com

My Youtube channel —  https://www.youtube.com/@ramu-narasinga

Learning platform —  https://thinkthroo.com

Codebase Architecture —  https://app.thinkthroo.com/architecture

Best practices —  https://app.thinkthroo.com/best-practices

Production-grade projects —  https://app.thinkthroo.com/production-grade-projects

Conclusion:

May be it is a common convention to use ‘_’ to ignore parameters but this was not my style. Now I know what to do, should I choose to skip declaring a parameter in a function. I simply write catch(_)