Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to find eaten Exception

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Does anyone know a tool that will scan all the source code and list all exceptions which got eaten without notice?

I am maintaining legacy code for my client and I noticed they have a bad habit of writing code like

} catch (Exception e) {
// Do nothing....
}

As I remember, there are tools like this which will tell you all those bad coding style, but I cannot remember the name. Would someone recommend a handy tool for me? Thanks
 
Marshal
Posts: 75637
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PMD?
 
Master Rancher
Posts: 4186
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Findbugs is another option. Also most IDEs will issue a warning for this by default, and you can configure them to consider it an error rather than warning, to make it easier to find this sort of thing.
[ December 03, 2008: Message edited by: Mike Simmons ]
 
Sheriff
Posts: 22644
123
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not that easy once you've put a piece of comment in there. Empty blocks and blocks with only comment in them are two different things. My Eclipse can only warn me about the first.
 
Mike Simmons
Master Rancher
Posts: 4186
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, Findbugs will never see the comment, since it operates by analyzing class files, not source. And in IntelliJ at least, it's possible to configure the inspection to either consider a catch with only a comment to be empty, or to consider it non-empty. The latter is the default, which I think is reasonable. Few people would bother to comment an empty catch block unless they're explaining why an empty catch block makes sense in this case - which shows they've at least considered the issue. If you don't trust the judgement of the coders who might have written such comments, then configure the inspection to ignore them, and can review each yourself.
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic