Community
Participate
Working Groups
So many people have asked how to write a declare warning / error to detect empty catch blocks, that this is clearly a desirable feature. But it's impossible with declare warning / error. And it's pretty hard in byte code (the old "what's the end of a catch block" problem). But it's not hard if you've got a compiler. So why don't we just add a new front-end compiler warning (works only when building from source) on swallowed exceptions. This would behave like the existing "undocumentedEmptyBlock" warning, except be specific to catch blocks so that you can turn it on without getting lots of warnings you don't want in many other places.
Surprise! I've got this working in my workspace. (Using a simple aspect to detect the condition and punt out the problem). Severity is controllable via Xlint:swallowedExceptionInCatchBlock. Hardest part was getting the JDT compiler options configured from an XLint setting! It works like this: catch(NoSuchMethodException ex) {} ^^ Blah.java:42:0 Exception swallowed in catch block We should try and get this picked up by the JDT themselves in time...
(you wouldn't believe how many swallowed exceptions in catch blocks there are in our test suite! :( )
Given all the warnings you can get out from the JDT compiler already - i'm surprised empty catch blocks isnt in there already... have you checked?
yep - they have "undocumented empty block" - which does catch empty catch blocks, but also a whole bunch of other stuff so you never turn it on. this one is just for catch blocks, so you can control the level for them independently. I didn't look in 3.2, but it will be a while before we bite that bullet anyway...
The default for this option appears to be "warning". I'd say "ignore" would be a better default, as this option doesn't relate specifically to aop - in fact our FFDC aspect in ajdt means we have lots of empty catch blocks, in which case the warning is rather annoying.
I see this bug is still open... are you going to change the default setting for this option? Enabling it by default isn't helpful, it just clutters up build reports.
default now changed to ignore, will be in the next build but I'm closing this bug report now instead of waiting since it's so minor...
Changing OS from Mac OS to Mac OS X as per bug 185991