+ 3

What is try and catch exception.?

4th Jun 2017, 9:26 PM
Amponsah Afriyie Agyare
Amponsah Afriyie Agyare - avatar
3 Answers
+ 4
try catch is basically error handling. Whatever is in the try block is what your program will try to run. If an error is caused, you can 'catch' the error and do something else instead of terminating the program. The error written in the catch clause is what the program will watch out for, if that kind of error is thrown then that is what catch block will run. Here's an example: https://code.sololearn.com/cOPb6Gxy1OQ9/?ref=app
4th Jun 2017, 10:37 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
The try block contains a block of program statements within which an exception might occur. A try block is always followed by a catch block, which handles the exception that occurs in associated try block. A tryblock must followed by a Catch block or Finally block or both. https://www.javatpoint.com/try-catch-block refer the above link which will be easy to understand and let me know if u have any doubts.
5th Jun 2017, 5:59 PM
Nanda Balakrishnan
+ 1
The basic thing is 'try the code to run'--- 'if any error occurs catch it' just to avoid uneven shut down or hanging of the compiler or programme. Example if there is a problem of zero division try and catch is the best way to tackle it making the programme stable.
5th Jun 2017, 8:17 PM
abhrodeep chanda
abhrodeep chanda - avatar