Forums Register Login

Related to exception handling

+Pie Number of slices to send: Send
Hi !
I've been making a stupid mistake while coding. After try/catch block i write code as if nothing has happened. For example i establish a network connection and retrieve some data from the server. Now after my try/catch block i'm using that data and go on as if nothing has happened. I don't think this is right. So i have come up with the following approach.
Suppose i have a boolean value and it is set to true in the try block. In the catch block it is set to false. So after my try/catch block I should test this boolan value. If it is true then there should be further processing and if it is false an error message should be displayed.
Do you think this is the right thing to do ?
Regards
Danish
[ July 05, 2003: Message edited by: Danish Shaukat ]
+Pie Number of slices to send: Send
why can't you display your error message in the catch block?
+Pie Number of slices to send: Send
I think that most likely, if the code following the catch block is something that shouldn't be executed after an exception, then either (a) your catch block is in the wrong place, or (b) you shouldn't catch the exception at all - declare it in the method's throws clause instead. (This will probably force you to decide whether or how to deal with the exception in some other method instead.)
E.g. if you have

consider replacing it with

or

[ July 05, 2003: Message edited by: Jim Yingst ]
+Pie Number of slices to send: Send
Thanks Jim
+Pie Number of slices to send: Send
Excellent examples, Jim! And Danish, if your code is any longer than Jim's, consider breaking it up to look just like his. (Had to try that new Graemlin!)
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 616 times.
Similar Threads
declare or handle
jtips exam2.No.28-Exception
Schema Validation
wait method doesn't working.
Try/catch/finally
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:55:35.