• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What to do with unlock on exceptions

 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say you have a lock on a record. Then during one of your operations,
lets say book, you run into a "Already booked exception" in your data class, before you throw the exception should you explicitly call unlock from your book function.
If you don't that record will remain locked?
my locking looks something like:

If book throws an exception, getDataObj().unlock(recordNumber,cookie) will never be executed. So the record remains locked.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest putting the unlock() in a finally, to ensure it eventually gets called whether subsequent operations succeed or fail.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should have thought of that, great idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic