The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Three Rules for Effective Exception Handling
Subject:  An endless war...
Date:  2003-12-05 00:30:25
From:  bitog


Good article... but a consideration:
proliferation of "throws" clauses tend to be a noise to developers.

I'm used to catch early specific exceptions, log them as much specific I can, and then re-throw a RuntimeException.
I can catch them later, displaying a message in a UI-dependent way, looking also to the exception cause (getCause() method)

For example:

public void aMethod(){
...
try{
...
...
}catch (SQLException s){
myLog.log("database errror");
throw new RuntimeException(s);

}catch (FileNotFoundException f){
myLog.log("wrong file name");
throw new RuntimeException(f);

}... and so on
}finally{
// release resources
}
}

What's your opinion?
Thanks

 Feed java.net RSS Feeds