I was doing final testing and I found an issue in my Data.java. Recently I changed my readRecord implementation from returning null to throw a RecordNotFoundException in the case when a record is marked as deleted. I just realized that I need to update other methods wherever they call readRecord.
Anyway, I am thinking just ask your guys opinion. During readRecord, if the record is marked as deleted, should we return null or throw RecordNotFoundException? I am inclined to throw exception in this case because it is not found.
During readRecord, if the record reading got some IO exception, I will throw RecordNotFoundException to wrap the inside exception.
Thanks to Roberto's Data testing tool. It prevents a lot of mistakes such as the above one.
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 I think if the record is marked as deleted, you should throw a RecordNotFoundException and no return (must not return null). And I handle the IOException by printStackTrace() and return null because it is not a requirement.
That's my thought.
But I throw an IllegalArgumentException (A RuntimeException) in the updateRecord(long, String, long) method. Is it OK?
Xin Gang Sun
boolean scjp_6 = true;
boolean scjd_URLyBird = willBeTrue();
The quote from instructions.html (shown by Xin) is "should", not "must". So i think you have the choice to throw exception or to return null. If it was a must-requirement, you didn't have any choice.
In my solution I throw the RNFE (and I also throw a RNFE when find-method doesn't find any matching record).
I don't have any problem with the IOException, because i use a record cache and I only have read/write operations at the start and end of the program. But i think you should wrap these exceptions in a RuntimeException, like the IllegalStateException (instead of wrapping it in a RNFE), because it's not really a RNFE but an illegal state of your database file