• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird - How to handle IOExceptions?

 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please any thoughts on how to handle IOExceptions when accessing the physical database file? My DB interface does only throws RecordNotFoundException.
I'm open to suggestions.
Thanks.
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Regarding my solution, I considered that an IOException at the Server side, is something unusual and unexpected at the client. That's why I chose to throw a RunTime error when an IOException occured at the server.
 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm considering wrapping them in some RuntimeException too.... but can what about just logging the errors... or just displaying some of the error information on the console (all parts of my application - server and client, run as GUIs).

More thoughts???
 
Arno Reper
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the same as Khaled Mahmoud...I try catch and throw a new one, a runtime one because its unusual...Because when the server started, the file was ok so something bad ( ) happened...
Arno
 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you throw a RuntimeException (wrapping the IOExceptions) from the Data class, do you declare it in the method definition (and is that allowed)? or do you just leave it out of the declaration (but know you have to catch it)?

What do you do with it on the client side?
...I'm using a service layer in between my Data class and my GUI class, what do you guys think about me catching the RuntimeException and throwing a checked Exception that the client code can catch?
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wrap the IOExceptions in a RuntimeException and throw them. I declare the RuntimeException in my JavaDoc and catch them in my client code. The GUI handles the exception in opening a dialog to inform the client/user.
 
Bod Toki
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so SUN doesn't mind you having an extra RuntimeException in the public interface of your DB implementation?
 
David A. Scott
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since RuntimeExceptions are unchecked they can be added to the implementation without breaking the interface contract.

They don't have to be declared or included in javadoc but doing so makes it easier for a client programmer.
 
Lucy Hummel
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Point to David,
RuntimeException do not have to be declared, but the life is easier for developer, if they know that RuntimeException R1 is thrown by method M1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic