| Hi! In program almost all lines we perform such steps in which exceptions can occur. So do we need to use try and catch after all statements. If so, then it will make our program tedious. What is the solution of this question? I am confuse in using try catch concept. Please help. Thanks |
Loading
ShankeyPosted Aug 31, 2010, 5:30 AM
I agree with Praveen Raveendran reply and further added it will protect your application from getting crashed. So that the user are not having wrong impression of your application. Try...catch clause allows your application to run smoothly even if there are chances of exception to occur like the same one if you want to perform division and you are taking it from user then there are chances of division by zero error. so to avoid that you have to write only your "Division code" in TRY....CATCH clause.
If it help you then mark it as an accepted.
Pasan RatnayakePosted Aug 31, 2010, 5:11 AM
For instance, if you get a divisable by zero exception everywhere, you could write a simple method that divides 2 numbers where you place the try-catch block. This way you can still perform the task everywhere in you application encapsulated in a try-catch block which reduces the repeated try-catch blocks. Of course there are occasions where this is not applicable but it could help.
Praveen Raveendran PillaiPosted Aug 31, 2010, 1:47 AM
No need to use try catch in your entire program. Try to find out the module where there is a chance of getting any error.
For example if a module is doing division action. There is a possibility of 0/0 error as well as dividebyzero error (eg: 5/0).
In these circumstances we need to use try catch statement. It would be better to catch the ArithmeticException as well as the General Exception.
I hope you understood.
Tanmay SarkarPosted Aug 30, 2010, 10:10 PM
the exception cases are,
user's input is not right form so there an exception occurred.
so we use try-catch to avoid it.
for more details please see the recommended articles section.
Thank you!
If it help you then mark it as an answer.