posted 3 years ago
I have just noticed that the code presented on the bottom half of page 853 of the study guide does not compile because of the too restrictive checked exception class caught in the catch block. The two-parameter get() method of the interface Future throws exceptions of the following checked exception classes: ExecutionException, InterruptedException and TimeoutException. I have discovered that catching only one of these exception produces a compile-time error, which reports that one other exception has not been caught or declared, as follows:
(1.) Catching only TimeoutException results in the error notice that InterruptedException must be caught or declared.
(2.) Catching only InterruptedException results in the error notice that ExecutionException must be caught or declared.
(3.) Catching only ExecutionException results in the error notice that InterruptedException must be caught or declared.
Since all the foregoing three checked exception classes extend the class Exception, the only resolution, to the vicious cycle of catching only one exception and having the corresponding compile-time error reported, is either to catch exceptions of class Exception in one catch block or use multiple catch blocks to catch each of the three exceptions in its own separate catch block.
Anyways, I just thought to note here that the code, as presented on page 853, does not compile (because the too restrictive/specific TimeoutException, rather than the more general Exception, was caught in the catch block).