• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic