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 |