Hi , I hava sevral question about my find and read method.
1.the read method.
(1) because the read method only can throw RecordNotFoundException. so i define a unchecked Exception called DataBaseAccessException .then i turn the IOExcetion into the unchecked Exception(DataBaseAccessException).Is it right? like this:
(2) My read method not only can read undeleted record but also can read deleted record.In other words the read method don't kown the record is a deleted record or not. is it right?
2.the find method (1) Can I reuse the read method in the data class. (2) Given i can reuse the read method. Can i turn the RecordNotFoundException throwed by read method into DataBaseException. is it reasonable? (3) could you give me some advice about the method?
my find method
[Andrew: removed some trailing tabs from the code block that were causing horizontal scrolling] [ August 09, 2005: Message edited by: Andrew Monkhouse ]
I don't have my exam instructions right in front of me, but I think they made it pretty clear that if a record is past the end of file or deleted, the read method is supposed to throw a RecordNotFound exception, *not* return an invalid record.
And for the find method, I believe you need to throw a RecordNotFound exception if there are no matches.
As for your code example, your try/catch block is too wide. If there is a single record that has been deleted, you will get a RecordNotFound exception, at which point you... throw an exception and exit the method? The right thing to do is to eat the exception, realizing that it just means it's a deleted record, and then move on to testing the next record.
Finally, it could be just me, but I think it's a little risky to turn in code with a labelled break statement. I was just reading Core Java, which seems to be a semi-official book on how to use Java, and in the section where they describe labelled break, there is a comment about how of course you would never do this... I would get rid of the need for a labelled break by adding a helper method to compare 2 records, or maybe to read a record and then compare it. [ August 09, 2005: Message edited by: Lara McCarver ]