Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find eaten Exception

 
Solo Chiang
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PMD?
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • 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 ]
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic