The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Exception-Handling Antipatterns
Subject:  I use log and throw
Date:  2006-04-06 08:33:39
From:  riccardocossu


I often use log and throw, but not in the way you post it; I use it like this:

catch(SomeException e){
log.error("I got exception: "+e.getMessage());
throw new SomeOtherException("I got exception:"
+e.getMessage(),e);
}

This way you don't print multiple stacktraces but keep track of the context in which the exception happened, along with some possibly meningful info, maybe about what method threw the Exception.
I think it is clearer than having to lookup the line where the exception was thrown.

Regards, Riccardo

 Feed java.net RSS Feeds