File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to find eaten Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to find eaten Exception" Watch "How to find eaten Exception" New topic
Author

How to find eaten Exception

Solo Chiang
Greenhorn

Joined: Sep 14, 2005
Posts: 18
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

Joined: Oct 13, 2005
Posts: 39784
    
  28
PMD?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Oct 27, 2005
Posts: 19759
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to find eaten Exception