+ 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 ??
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
+ 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.
+ 1
I see ... so exceptions are basically helping us to detect the exact error withoutâ the termination of program .. thanx :)