Lessons from open-source: try..catch(_)?
Ramu Narasinga
Posted on April 10, 2024
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:
- There’s no further processing required when an error is encountered.
- Implement a fallback that does not rely on error.
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.
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(\_)\
Get free courses inspired by the best practices used in open source.
About me:
Website: https://ramunarasinga.com/
Linkedin: https://www.linkedin.com/in/ramu-narasinga-189361128/
Github: https://github.com/Ramu-Narasinga
Email: ramu.narasinga@gmail.com
Posted on April 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
April 2, 2024