Hi all, I have B&S application and a "clean" method signature for the "find" method that does not throw RecordNotFoundException. The problem is as follows : while checking if the records are matching the given condition, it can be that a record is deleted and the RecordNotFoundException is thrown. The solution that I have is to swallow the RecordNotFoundException and to ignore the record that was just deleted Do you think that this is acceptable ? Does anybody have a better solution ? Thank you very much in advance, Liviu
Originally posted by Liviu Carausu: Hi all, I have B&S application and a "clean" method signature for the "find" method that does not throw RecordNotFoundException. The problem is as follows : while checking if the records are matching the given condition, it can be that a record is deleted and the RecordNotFoundException is thrown. The solution that I have is to swallow the RecordNotFoundException and to ignore the record that was just deleted Do you think that this is acceptable ? Does anybody have a better solution ? Thank you very much in advance, Liviu
I am also doing the Bodgitt and Scarper assignment, but my find method does throw a RecordNotFoundException like so:
In your case, you can handle a RecordNotFoundException inside your find method by logging a message indicating a deleted record. Swallowing an exception in your catch block and doing absolutely nothing is almost always bad practice and could cost you some marks.
Or, probably better, you could wrap the RecordNotFoundException inside a RuntimeException or other subclass (remember RuntimeException can be thrown without an exception declaration). The exception then is handled outside the find method, perhaps by showing a message to the user that the record, that is being searched by one user, was just deleted by another user.
Hope this helps. If anyone has a better solution or thinks I'm wrong, please correct me. [ February 07, 2008: Message edited by: Aaron John ]
in my opinion also the find method throws RecordNotFoundException but in the real life you not throw it , because it is your responsiblity to return all matching record. and your internel implementation not based on index or something other than the sequentil data file.
so may be the evaluator but the RecordNotFoundException in the signature of the find method , i think the find method must not throw RecordNotFoundException at ALL.
what you think.
Best Regards. Mohamed Darim, SCJP, SCJD in progress ... ( upload 1/april/2008).
How do you handle the cases where no records match the search criteria? I would like to just return null, but the method signature could be interpreted like we should throw a RecordNotFoundException? What do you think?
please don't return null , because the caller expect an array but you can return an empty array or list in bussiness class. so the caller can safty iterator on the return array or list.
for RecordNotFoundException your decision must be documented. but i think just returning empty array or list is enough tell about that.
please don't return null , because the caller expect an array but you can return an empty array or list in bussiness class. so the caller can safty iterator on the return array or list.
regards.
Hi Mohamed, Yes that's true, thanks for pointing it out.
In my opinion, the exception should be thrown in the case search result is empty and follow the interface contract. That's the only reason for the exception there. The caller is going to have a catch clause for that anyways.
In my opinion, the exception should be thrown in the case search result is empty and follow the interface contract. That's the only reason for the exception there. The caller is going to have a catch clause for that anyways.
you are right by following the interface contract BUT from my description regarding RecordNotFoundException "... should do so if a specified record does not exist or is marked as deleted in the database file.."
So this description is not true or clear about the job of find method. also if the caller is catching the FNFE .. and the FNFE will not throw in find ! what is the problem ?
Sorry for the delay.. What meant about following the contract is the "should do so if a specified record does not exist or is marked as deleted in the database file".
In the find method, the "specified record" is related to the criteria array. Hence, if no records are found (the specified record - though it could mean more than one), then the exception should be thrown.
Regarding this post, I have a question and I am not how sure how to handle it
For the GUI search, it has a AND/OR requirement for hotel name and location (urlybird)
if find method from the Data class will throw RNFE, if no record match the criteria.
then the find method for Or, I am using 2 find methods from the Data class and union the result.
If one of the find method (e.g. hotel name) return a RNFE. I am thinking if i should swallow the exception. I agree that it is not a good idea to do nothing with the Exception caught.
How should I handle it ? as there may be match record for the other find method (e.g. location)
In my find method there is also no Record Not Found exception and there are comments above the method " A null value in criteria[n] matches any field value".
In my method I calculated total number of records then it checks in all not deleted records so I dont need Record Not Found exception for find method. But I used readRecord() mehtod inside the find() method, this readRecord() method throws RecordNotFoundException.
Secondly if null value is passed in method's array parameter i.e criteria[n] then all record number are returned as its asked in methods signature. Then on client side it does filteration again and passes the exact matched records in JTable. If no match found then only fields names as headings appear at the top of JTable.
Best Regards!
Post by:autobot
Shiny ad:
a bit of art, as a gift, the permaculture playing cards