File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Should I throw RecordNotFoundException in lock()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Should I throw RecordNotFoundException in lock()?" Watch "Should I throw RecordNotFoundException in lock()?" New topic

Should I throw RecordNotFoundException in lock()?

Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Hi all,

public long lockRecord(long recNo) throws RecordNotFoundException

According lock method signature provided by Sun, it throws RNFE, if I don't want to check invalid record and discard RNFE in my implementation, is it OK?

Thank you,
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
I can think of one good reason why you should throw the RecordNotFoundException from lockRecord: A client may in the future want to lock a record down indefinitely, without calling any other methods on the data object before or after locking. This might happen if a subcontractor was suspended and could not be used for a while. In this case, all the client would want to do is call the lockRecord method, which is public. The client could not count on discovering that a record did not exist by calling other methods like readRecord because all the client wants to do is lock the record. Thus, the client should be made aware that a record does not exist if it tries to lock a record, and hence the RecordNotFoundException should be thrown in lockRecord.

Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
I agree. Here's the link:
subject: Should I throw RecordNotFoundException in lock()?
It's not a secret anymore!