Originally posted by Mingwei Jiang:
In my DB interface, the unlock method also throw RecordNotFoundException. I think it's reasonable for the lock and some other methods to throw this exception, like read, update, delete, because it is reasonable to first verify the existence of the record, then lock it or do some modification on it. But why unlock method need to throw RecordNotFoundException? I put locked records in a hashmap, and if unlock(recNo, cookie) is called, I'll check if the recNo is in the hashmap, if not, it will simply return, otherwise, it will remove the recNo in hashmap and return. I just don't know why bother throwing this exception. trying to verify the existence of the record will possibly cause IOException and maybe lower the performance.
I want to ask can I never throw this exception in code, though it was declared by SUN?
Originally posted by Julian Kennedy:
Hi Mingwei,
My spec for B&S states that you MUST implement the interface. Bearing that in mind I wouldn't want to omit the exception even if I could justify it in my design choices. The worst case scenario is that it could cost you 150 bucks (or whatever) to resubmit!
I think there's a good reason to have the exception anyway. If your app is trying to unlock a record that isn't locked then that's surely an error condition, though perhaps not a very serious one. If you don't find the recNo in the HashMap, just throw the exception. No big deal. Your calling code can then just catch it and quietly log it as a warning, if you choose.
How does that sound?
Jules
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by Anton Golovin:
I find in my project I have to resort to exceptions where any error causes my program to not execute something very important. I have to do this since there is no other good way to make the error known to higher-level functionality. RecordNotFoundException fits into this scheme quite well.
Originally posted by Julian Kennedy:
Peter's solution is an option that I have considered in my design (which I haven't implemented yet). Of course what we really want to do is to use checked exceptions. Clearly we can't change the DB interface, but can we use checked exceptions without changing it?
Is this code legal?
I only ask as I don't have access to a Java compiler here to check it out myself.
Jules
Their achilles heel is the noogie! Give them noogies tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|