REQUEST: better empty catch in better exception handling
Bruce Chapman
brucechapman at paradise.net.nz
Wed Mar 25 02:07:38 PDT 2009
I think a better solution to this problem is to add a new method to
Throwable thus
public final void ignore() {}
And then you can explicitly ignore an exception like this
}catch(SomeException ex){
ex.ignore();
}
I would hope that hotspot could inline that quite easily :)
I intend to suggest this for the small API changes process which is
coming soon.
Bruce
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