+ 2

Is exception a help or an extra lines of code ?

I just learned that exception keywords like try and catch can help me in catching errors and reduce the ambiguity of the code ... but doesn't it increases the lines of code ... because the error can be pointed out when we build and run our program ... then why is it necessary to use this facility ??

12th Mar 2017, 8:49 AM
Ali Abbas
Ali Abbas - avatar
3 Answers
+ 3
It is helpful in the long run, Example :- Lets say you are playing a multiplayer game.And you disconnected. Usually the msg displayed is "Connection Error". What if it is "compile error : java.awt.somethinglikethat.issue. resolve this."That doesnt help, hence exceptions are useful
12th Mar 2017, 8:53 AM
Meharban Singh
Meharban Singh - avatar
+ 1
While handling Exception we print message which user can understand even without having any knowledge about programming language. Like when we get error like : NullPointerException, IndexOutOfBoundException we know that what it actually means but user will not able to understand it to help our user why we are getting this error you can replace this error message by handling exceptions with something meaningful.
12th Mar 2017, 12:17 PM
Utkrisht Sinha
+ 1
I see ... so exceptions are basically helping us to detect the exact error without​ the termination of program .. thanx :)
14th Mar 2017, 7:12 PM
Ali Abbas
Ali Abbas - avatar