Softening exception in try-with-resources [message #901908] |
Wed, 15 August 2012 01:06 |
|
I've been making use of the new try-with-resources syntax when I upgraded to AJDT 2.2.0 a few weeks back (and could start using Java 7 in my AspectJ projects), but the aspects I wrote to soften IOException don't seem to catch the automatic close() created by the new syntax:
try (BufferedReader reader = new BufferedReader(new FileReader("test.txt"))) {
System.out.println(reader.readLine());
}
...
declare soft: IOException: within(*)
Eclipse reports a compile error on the try... line, saying: "Unhandled exception type IOException thrown by automatic close() invocation on reader". The only way I've managed to get around this is to add a catch clause to the try for the IOException, or to have the method throw IOException, which kind of goes against the reason I did the exception softening in the first place (to cut down on throws or catch clauses).
Is there another way to soften the automatic close while using the new syntax?
|
|
|
|
|
Re: Softening exception in try-with-resources [message #901931 is a reply to message #901919] |
Wed, 15 August 2012 06:53 |
|
The error appears in both the problems view and in the editor ('reader' in the example above is underlined red and the error icon is also showing in the left of the line). No additional exceptions/errors show in the Error Log (only info messages about other things like how long weaving/building the rest of the workspace took). Compliance level is set to 1.7.
I just tried compiling the code with ajc via the command line and I get a compile error with the same message and line number, so if there's a problem it might be with AspectJ.
[Updated on: Wed, 15 August 2012 06:55] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11518 seconds