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