Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Exception handling approach. Please comment!!  RSS feed

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, after a long time
Is this a good approach doing like this?

Say suppose while doing a read or write on database file, there are chances of either getting a IOException or EOFException. If either of exceptions are thrown, then I want to inform client/server accordingly that
database write operation is faield and the client/server should stop immediately not to corrupt any data.
So my question is, if either exception occurs am doing the same thing and also if a generic exception "Exception" occurs will do the same thing. Is there any need to catch all three individually and throw the same exception back to client? Or is it advisable to just keep "Exception" catching there?
The main reason for catching "Exception" is that if a NullPointerException occurs then also client/server is informed. Or should I just catch only those exceptions that ARE ACTUALLY thrown in try statement?
Please comment on the approach. Thanks.
[ April 22, 2004: Message edited by: Satish Avadhanam ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satish, EOFException extends from IOException - you will never catch it in that try-catch block
I say only catch the exceptions that are thrown. In that case, if there are any unchecked exceptions that are thrown, like ArrayIndexOutOfBoundsException, you will know about it. Otherwise, that code will just eat it up. Of course, at the last level of exception handling, you'll want to catch any exception before presenting it to the user.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Min.

Originally posted by Min Huang:
Satish, EOFException extends from IOException - you will never catch it in that try-catch block

I meant the other way around. Maybe SCJD final week(or couple of days) pressure, could'nt see it

I say only catch the exceptions that are thrown. In that case, if there are any unchecked exceptions that are thrown, like ArrayIndexOutOfBoundsException, you will know about it. Otherwise, that code will just eat it up. Of course, at the last level of exception handling, you'll want to catch any exception before presenting it to the user.


OK, Thanks.
Hey Min, did you took the essay exam or still "Extremely worried"
Good Luck to you on exam
 
Min Huang
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hey Min, did you took the essay exam or still "Extremely worried"


I was worried after taking the exam
(Why isn't there a :nervous: smiley? I'll use a combination of frown and embarassed to represent that...)
Anyways, yup, there's nothing I can do now about the exam, so... I am not worrying. I have a new exam to worry about (SCBCD)
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Min Huang:

Anyways, yup, there's nothing I can do now about the exam, so... I am not worrying.

Chill out and stay

I have a new exam to worry about (SCBCD)
Compared to SCJD, that should be easy relatively. Good Luck.

 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Also if some IOException occurso or any FatalException occurs, I want to shutdown the server. Can I call something like
ShutdownService.stopServices() from db package, where ShutdownService is in network package. Is this OK?
Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!