Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Need some clarification on RecordNotFound Exception

 
james pang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need some feedback from you concerning the usage of RecordNotFound Exception.

My assignment is:
-----------
public String [] read(int recNo) throws RecordNotFoundException;

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

My question is : is it alright to throw RNFE only when a specified record does not exist and return null when is marked as deleted in the database file?

Anyone disagree ?

Regards,
James
 
Wei-ju Wu
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to return null in any case ? I think the specification is clear in this case: if it is marked deleted, throw RecordNotFoundException.
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.
-----------

My question is : is it alright to throw RNFE only when a specified record does not exist and return null when is marked as deleted in the database file?


Hi James,

I think it is not alright. The specification is very clear that if it is marked as deleted, the exception should be thrown. Although this requirement does not use the must-word, I would not take my chances on this one if I were you.

Also, from a software engineering point of view, it seems as a bad choice to me. It does not really matter whether the record does not exist at all or is marked as deleted: bottom line is that the record is unavailable and cannot be accessed.
The situations where your code needs to make this distinction, should be handled in lower-level parts of the code; not in this interface.

Frans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic