*
The moose likes Java in General and the fly likes catch/finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "catch/finally" Watch "catch/finally" New topic
Author

catch/finally

divya madala
Ranch Hand

Joined: Jan 10, 2001
Posts: 61
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

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Have you tried it yet? Did you need another try/catch block around the wait()? It's a little ugly, but perfectly normal.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: catch/finally