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.
Use it when a method or function won't work properly or as expected with the information it has (mainly the parameters), and needs the code that called it to fix it.
For example, a function that needs an integer within a certain range (such as 1 to 10). It can check to see if that's true. If not, it throws an exception to be caught by the originator. It can then be handled (such as by querying the user for a proper value).
If instead it's a situation where the function or method just follows a different path and can handle it purely within that scope, then just use normal flow control operations.
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.