Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

catch/finally

 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a wait statement in my catch block. (when I catch the exception, I want wait for 10 mntues before I start it again). I have some variables to be updated at "finally". My question now, will it wait for that time (specified in catch) before it updates the variables at finally block?
I have code as follows

will it wait for those 45 min? to incerement a?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Assuming that nothing interrupts your "waiting" thread, it will work as you expect.
The "finally" block of code always is executed after the "try" block and the "catch" block if an exception is caught. So, if you put your thread to sleep for some period of time in your "try" block, the "finally" block will only execute after that period of time.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it yet? Did you need another try/catch block around the wait()? It's a little ugly, but perfectly normal.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An exception can be thrown if your sleeping thread is waken up by another thread, so you need to either declare or catch it. I usually catch it rather than declare to throw it, especially if I know there aren't other threads around to wake it up.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic