Page 1 of 1
					
				About Question enthuware.ocpjp.v7.2.1557 :
				Posted: Thu May 02, 2013 2:09 pm
				by arnoldnitesh
				I don't understand how catch block will be execute here ? i can't see any reason that will throw InterruptedException.
			 
			
					
				Re: About Question enthuware.ocpjp.v7.2.1557 :
				Posted: Thu May 02, 2013 3:09 pm
				by admin
				Right. It is not throwing InterruptedException. The assignment is after the catch block.
-Paul.
			 
			
					
				Re: About Question enthuware.ocpjp.v7.2.1557 :
				Posted: Thu May 02, 2013 3:19 pm
				by arnoldnitesh
				Thank you 

 
			 
			
					
				Re: About Question enthuware.ocpjp.v7.2.1557 :
				Posted: Sun Jan 08, 2017 1:01 pm
				by sir_Anduin@yahoo.de
				what would be the answer if the assignment where in the catch block?
			 
			
					
				Re: About Question enthuware.ocpjp.v7.2.1557 :
				Posted: Sun Jan 08, 2017 7:24 pm
				by admin
				If the assignment were in the catch block, you would have to interrupt the hello thread while it is sleeping. You can do that by calling   t.interrupt(); in main.
However, main may still fail to print 20 because the main thread could keep running and print 0 before the code for assignment gets to run.
So you could add t.sleep(2000); after t.interrupt() to see that assignment is done and then the value is printed.
You should try out various options to see how it works.
HTH,
Paul.