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.

catch(_)

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.

catch(_) usage

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(_)

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
are-hackers-watching-your-screen-right-now?

Are hackers watching your screen right now?

Next Post
left-and-right-shift:-bitwise-operators-in-python

Left and Right Shift: Bitwise Operators in Python

Related Posts
top-46-learning-sites-for-you-

Top 46 Learning Sites for You 💖

www.primetechie.com www.lynda.com www.udemy.com www.udacity.com www.coursera.org www.w3schools.com www.thenewboston.org www.programmr.com www.codeavengers.com www.codeschool.com www.learnstreet.com www.teamtreehouse.com www.sqlzoo.net www.codehs.com www.teamtreehouse.com www.html5rocks.com www.codepen.io www.sitepoint.com…
Read More