Jon Camilleri wrote:Well is it safe to remove the catch? In any case the 'ball' does not seem to move anywhere with this code, when I remove the catch clause.
So, let's look at the error message from the compiler:
Read it carefully and try to understand it. What does it say? It says that in the try-block there isn't any code that can ever throw InterruptedException. In other words, catching InterruptedException is unnecessary here, because it will never be thrown from the try-block.
So, what do you think, is it safe to remove the catch?
Jon Camilleri wrote:Well is it safe to remove the catch? In any case the 'ball' does not seem to move anywhere with this code, when I remove the catch clause.
So, let's look at the error message from the compiler:
Read it carefully and try to understand it. What does it say? It says that in the try-block there isn't any code that can ever throw InterruptedException. In other words, catching InterruptedException is unnecessary here, because it will never be thrown from the try-block.
So, what do you think, is it safe to remove the catch?
Horstmann reads that the catch is recommended to be there, whilst the compiler thinks that it is not.
Since the code in the try-block will never throw InterruptedException, catching this exception is unnecessary, you should remove the catch for that exception. If the code is exactly copied from the book (and not modified in any way) then that is a mistake in the book.
The compiler is always right. (Unless there is a bug in the compiler, but it will be very, very rare to encounter a bug in the compiler).
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
posted
0
just double check that you have not mistakenly commented the below statement which is the cause for the error.