REQUEST: better empty catch in better exception handling

rssh at gradsoft.com.ua rssh at gradsoft.com.ua
Tue Mar 24 18:22:25 PDT 2009


 Yet one problem with extension handler: rare we need catch exception but do
nothibg in catch statement. (i. e. do not log)
Example is code like next snipset:

try {
  something=searchFirst(condition);
}catch(NotFoundException ex){
  // do nothing. search better
}

if (something!=null) {
 try {
  something=searchSecond(condition);
 }catch(NotFoundException ex){
  // do nothing. search better
 }
}

>From other side, we prefer do not have in codebase code with empty
exception handling and use special tools to detect empty catch braclets
and warn about ones.
 For now,   we use ';' to mark, that this empty catch is really empty
catch and not error or unfinished refactoring. I.e.:

if (something!=null) {
 try {
  something=searchSecond(condition);
 }catch(NotFoundException ex){
  // do nothing. search better
  ;  // ';' tell javachecker do not complain about empty catch.
 }
}


But this is ugly.
Of course, is simple use annotation
@SuppressWarning("empty-catch")  but javac compiler does not warn about
empty catch-s.

So, question to community: is it possible to extend exception handling
proposal by adding optional conventions
 - warn about empty catch-s
 - specify rare cases, when empty catch is really needed. ?

For example, this can be @EmptyCatch annotation, which mark catch block
empty. i.e.
try {

}catch(@EmptyCatch  NotFound | FoundNotAsILike ex ){
}
and effective do nothing.







More information about the coin-dev mailing list