Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Softening exception in try-with-resources
Softening exception in try-with-resources [message #901908] Wed, 15 August 2012 01:06 Go to next message
Emanuel Rabina is currently offline Emanuel Rabina
Messages: 3
Registered: August 2012
Junior Member

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 #901918 is a reply to message #901908] Wed, 15 August 2012 05:04 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 369
Registered: July 2009
Senior Member
From your description, I can't tell if this is a problem with AJDT or AspectJ.

Do you see the error appearing in the problems view, or is it only in the editor? Also, do you see any exceptions in your error log?
Re: Softening exception in try-with-resources [message #901919 is a reply to message #901918] Wed, 15 August 2012 05:05 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 369
Registered: July 2009
Senior Member
Also, (and this may be silly and obvious) make sure that your source compliance level is set to 1.7.
Re: Softening exception in try-with-resources [message #901931 is a reply to message #901919] Wed, 15 August 2012 06:53 Go to previous messageGo to next message
Emanuel Rabina is currently offline Emanuel Rabina
Messages: 3
Registered: August 2012
Junior Member

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

Re: Softening exception in try-with-resources [message #902020 is a reply to message #901931] Wed, 15 August 2012 14:08 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 369
Registered: July 2009
Senior Member
This does sound like an aspectj problem. Since this is a forum for AJDT, you'd get a better response on the aspectj mailing list or by raising a bug on bugzilla.

Mailing list is here:
http://eclipse.org/aspectj/userlists.php

Bugzilla is here:
https://bugs.eclipse.org/bugs/
Re: Softening exception in try-with-resources [message #902314 is a reply to message #902020] Fri, 17 August 2012 00:47 Go to previous message
Emanuel Rabina is currently offline Emanuel Rabina
Messages: 3
Registered: August 2012
Junior Member

Thanks Andrew, I've raised a bug on Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=387444
Previous Topic:Android/Aspectj w/Google Maps ant build fail
Next Topic:Help
Goto Forum:
  


Current Time: Fri Oct 24 15:47:16 GMT 2014

Powered by FUDForum. Page generated in 0.01988 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software