REQUEST: better empty catch in better exception handling

rssh at gradsoft.com.ua rssh at gradsoft.com.ua
Tue Mar 24 22:41:33 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.
>

Yes, this is possible. But it's shows, that somebody at least seen this
empty catch on exception, warned that empty catch are extremally rare and
do decision: add exception handling code or such annotation.

I. e. this is not ideal, but better than nothing. I'm afraid than more
 ambitious target (let's compiler automatically distinguish difference
between empty catch block by mistake and by need) is too hard for solving
during this week.


> 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