• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RNFE in update /delete method

 
pramod karnani
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

Should we throw RNFE in update/delete method ?

but signature of update /delete is in instruction like :


public void update(int recNo, String [] data)
throws RecordNotFoundException;


// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) throws RecordNotFoundException;



but signature of lock method

// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
// Releases the lock on a record.

so I think lock method will always be called before update/delete , correct?

So lock method is already throwing RNFE so no need to throw RNFE in update/delete .

correct?

Please reply .


Regards,
Pramod
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to throw rnfe for update delete if you do it in lock
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pramod,

You don't even have to throw one in unlock-method.

Kind regards,
Roel
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, if you do everything correctly (calling lock()/update()/delete()/unlock()), it isn't really necessary to throw it... but it could make sense throwing it when you call, for instance, the update() method isolately. This way, the client could know that the record to be updated doesn't even exist.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:but it could make sense throwing it when you call, for instance, the update() method isolately

If you try this, you should get a SecurityException (or an IllegalStateException or another exception), because you are not using the API correctly. Each call to update/delete should be surrounded with a call to lock and unlock. That's my opinion about it (and explained it in dept in my choices.txt)

Kind regards,
Roel
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:If you try this, you should get a SecurityException (or an IllegalStateException or another exception)...


Maybe it could make sense to throw the exception before it. I myself throw the RNFE if the record to be locked doesn't exist. Then I proceed and verify if the record is locked. It it isn't locked, then I throw the IllegalStateException.
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should only throw exception that are checked if the user is not doing something abusive to the API. Any API abuse is RuntimeException candidate because a user cant be expected to recover seeing as they already violated the API. Hope you understand better now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic