• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

NX: Exceptions in Data class

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
The specification says:

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


So, if the DBMain interface declares the methods like that:

How can I notify an IOException when deleting from the database file?

Regards,
Fl�vio.
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my initial design and my initial implementation, I do the following:

However, I am not suggesting that this it the best way, although it is
one way of doing it.
If, right at this very minute, you read over the last 15 posts in this news
group, you will find a posting about handling exceptions which Phil
gave a very strong, positive response to. I plan to study this post in
detail during my next iteration phase. It turns out that I have this
posting link:
Topic: Exception handling using socket connection
https://coderanch.com/t/185087/java-developer-SCJD/certification/Exception-handling-socket-connection
I would still recommend looking over the last 15 posts, as this particular
topic item has been coming up a lot recently, and there was other good
advice offered by others.
Again, the "last 15 posts" means as of right at this minute (since the order
of the postings changes over time).
Thanks,
Javini Javono
 
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fl�vio,

Originally posted by Fl�vio Fran�a:
How can I notify an IOException when deleting from the database file?


These are the two main ways to do this:
1) Catch the IOException and throw a RecordNotFoundException that chains (or wraps depending on what your RecordNotFoundException class supports)the IOException as its cause. For example:

2) Derive a subclass of RuntimeException. Catch the IOException and throw a subclass of RuntimeException that chains the IOException as its cause. For example:

Method 1 requires the client to handle the RecordNotFoundException, but it's up to the client to examine the cause of the exception.
Method 2 doesn't require the client to handle the exception, but doesn't make the implicit claim that an IOException problem is a variety of RecordNotFoundException.
On balance I think method 1 is the better solution in this case. Others may disagree.
 
Flavio Nobili
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for helps!
George,

On balance I think method 1 is the better solution in this case. Others may disagree.


Yes, I prefer method 1 too, but it sounds strange on the method create wich throws a DuplicatedKeyException. So, I think I'll use the second one.

Regards,
Fl�vio.
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fl�vio,

Originally posted by Fl�vio Fran�a:
Yes, I prefer method 1 too, but it sounds strange on the method create wich throws a DuplicatedKeyException. So, I think I'll use the second one.


That's a good point about the create method. I used method 1 to wrap the IOException within a DuplicateKeyException, but I wasn't as happy doing so as I was wrapping IOException in RecordNotFoundExceptions for the other database methods. I was willing to go through these contortions in order to get the benefit of having a checked exception. Of course, I understand if someone's not willing to do the same. The inability to change the Sun interface leaves us with less than ideal alternatives. You have to go with the one that makes the most sense to you.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The find method doesn't throw any exception, that made me choose the RuntimeException solution.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have done it a little diffrent to most of you. I made RecordNotFoundException extend IOException. I still do

within my data class.
I have also made RecordNotFoundException extend IOException. This make it a little easier with my DBAdapter.
Any thoughts?
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic