REQUEST: better empty catch in better exception handling
Jeremy Manson
jeremy.manson at gmail.com
Tue Mar 24 22:21:15 PDT 2009
Do people do empty catch blocks by mistake? They always think it is
right, even if it isn't. I just imagine people sprinkling this
annotation everywhere and not getting anything out of it.
Jeremy
On Tue, Mar 24, 2009 at 6:22 PM, <rssh at gradsoft.com.ua> wrote:
>
> 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