Unreachable catch classes

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Apr 28 11:56:36 UTC 2011


On 27/04/11 13:51, Maurizio Cimadamore wrote:
> On 27/04/11 09:18, David Holmes wrote:
>> Special-casing Throwable wouldn't be sufficient as people may use 
>> Exception instead. 
> I guess this doesn't invalidate the argument - we could special-case 
> Exception AND Throwable, since they are already treated specially in 
> the language...
>
> Maurizio
Hi
after a discussion with the team, we have decided that we will relax the 
new javac warnings so that they will *not* be generated for those catch 
clauses catching Exception or Throwable.

This is similar to how javac has always handled a similar case (error 
message: 'exception never thrown in body of try'); for example, this 
code compiles:

try { }
catch (Exception e) { ... }

while the following does not compile:

try { }
catch (IOException e) { ... } //error IOException never thrown


The code generating the newly added javac warnings will be changed 
accordingly; for example, the following will compile w/o warnings:

try { throw new FileNotFoundException(); }
catch (FileNotFoundException fnf) { ... }
catch (Exception e) { ... }

while the following code will still emit a 'dead catch' warning:

try { throw new FileNotFoundException(); }
catch (FileNotFoundException fnf) { ... }
catch (IOException e) { ... }


This should accommodate all weird cases of checked exceptions not being 
declared (as in Class.newInstance).

Maurizio








More information about the core-libs-dev mailing list