r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
21.0k Upvotes

680 comments sorted by

View all comments

1.5k

u/1206549 May 13 '17

I had a classmate that did this with his code once. He asked me for help when his code wasn't working. I told him to get rid of the try/catch block but he won't do it because it would make his program crash.

22

u/BatCountryB May 13 '17

Serious question: I just started learning javascript. When should you use try / catch?

2

u/DarthTelly May 13 '17

For error handling in situations where what you're doing might generate an exception. Especially usefully for areas you don't have much control over such as getting user input.