0

What is purpose of try and catch statement In java ?

20th Jan 2017, 11:44 PM
Taha Mahmood
Taha Mahmood - avatar
2 Réponses
+ 4
Try/catch is to catch errors. Normally the program would just stop once it gets an error somewhere (for example wrong input or something). If there's an error inside the try it will continue with the catch-block and what's after.
20th Jan 2017, 11:55 PM
Robobrine
Robobrine - avatar
+ 2
if/when an error happens while executing the code within the "try" block, the code within the "catch" block is executed (eg display error message, change the value of a variable...) instead of just crashing the program.
21st Jan 2017, 8:46 AM
ifl
ifl - avatar