• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Related to exception handling

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why can't you display your error message in the catch block?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jim
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!)
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic