Community
Participate
Working Groups
BETA_JAVA7 In the following scenario void foo(String name, boolean b) throws FileNotFoundException{ ff = new FileInputStream(name); try (FileInputStream fis = ff) { // see here throw new IllegalArgumentException(); } catch (IllegalArgumentException e) { e.printStackTrace(); } System.out.println("SUCCESS"); } I get an unhandled IOException error message. This is confusing at first, since you'd think fis == ff is a harmless assignment which wouldnt throw IOException.Only on some deliberation it is clear to the user that this IOException corresponds to the close() call which is generated for the resource 'fis' by the compiler and thus it is necessary to handle the IOException. We should perhaps make it clearer by changing the error message to explain the IOException.
Yes, agree that state of affairs today can be confounding and needs improvement.
Created attachment 197680 [details] proposed fix v1.0 + regression tests Added a new error message "Unhandled exception type {0}, caused due to auto close of resource {1}" for exceptions raised ONLY during the auto close of a resource. Note that if the resource is explicitly closed inside the try block, we will report the old "Unhandled exception type {0}" error.
Released in BETA_JAVA7 branch
Created attachment 197725 [details] minor update Changed wording of error message according to Srikanth's suggestions. It now reads "Unhandled exception type {0}, caused by automatic closure of resource {1}"
> "Unhandled exception type {0}, caused by automatic closure of resource {1}" Does it really need to use the word "closure" that will likely be used for something different in Java 8? We already have: Unhandled exception type {0} thrown by implicit super constructor How about this? Unhandled exception type {0} thrown by automatic close() invocation on {1}
(In reply to comment #5) > How about this? > Unhandled exception type {0} thrown by automatic close() invocation on {1} Sounds good to me.
(In reply to comment #5) > How about this? > Unhandled exception type {0} thrown by automatic close() invocation on {1} Done.
Verified using "Eclipse Java Development Tools Patch for Java 7 Support (BETA) 1.0.0.v20110623-0900 org.eclipse.jdt.patch.feature.group Eclipse.org"