• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

catch/finally

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic