• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S Data impl. => Specific Exception and Constructor arguments

 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

=> Anyone created more specific exceptions extending RecordNotFoundException ?

Something like:
- RecordDeletedException
- RecordOutOfBoundException
- RecordReservedException (update and delete could throw that when the record has not been locked previously).

Of course they would be of type RecordNotFoundException. Am I missing anything wrong with that ?

=> Any problems with passing the db-filename in Data's constructor (or in getInstance in case of singleton..)? Something I might have missed, related to tests that SUN would perform ?

Well, that's a start, I'll be able to survive few days with these 2 questions.

Thanks in advance
Alex
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DB file name can be passed to the constructor, i don't see why that would cause a problem.

I believe that RecordReservedException shouldn't extend RecordNotFoundException, RecordReservedException has a different meaning from being unable to find the record.

other types of exceptions are possible to use, BUT i would say stick with the RecordNotFoundException without extending as there is no need to specify detailed reasons.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I take the update method for instance, considering the "lock" is suppose to allow a record to be updated by only 1 thread at a time.

=> Do you think the update method should throw an exception if someone does not lock the record before ?

If so, it is only supposed to throw "RecordNotFoundException"..

Either I :
- don't throw nothin in this case
- throw RecordNotFoundException
- throw a sub class of RecordNotFoundException
- throw a runtime exception

Any opinion on the 4 options ? I know it was discussed in other threads, but I feel the "sub class" option was not discussed.

Thanks,
Alex
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although exceptions have been discussed so many times on this forum it is still a topic of discussion, i don't blame you i always have my questions on exceptions.

what i did is that i took one of the advices that i found here on the forums: throwing a RuntimeException. that way you don't violate the contract plus it makes more sense than throwing a RecordNotFoundException.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll buy that! thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic