Test.java:9: exception java.lang.InterruptedException is never thrown in body of corresponding try statement catch(InterruptedException t) ^ 1 error If you change the IOException with Throwable or Exception or RuntimeException then no compile error occurs. So what's the rule here?? Does the compiler only check on the Checked Exceptions if it's actually thrown or not? but not the Unchecked Exceptions??
Yes, that's one of the things it means to be a "checked" exception. It is not legal to try to catch a checked exception that will never be thrown. It is always legal to catch an unchecked exception. It's also legal to catch Exception and Throwable, since those classes have both checked and unchecked subclasses. (By the way, are you sure that error message comes from the code you are showing us? The code catches IOException but the error message refers to InterruptedException.) [ October 18, 2002: Message edited by: Ron Newman ]
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
posted 16 years ago
Oh sorry, I was trying different Exception, probably copied the wrong error from my editing tool "Textpad"