Community
Participate
Working Groups
Eclipse Platform Version: 3.1.0 Build id: 200411050810 How to reproduce: compile this class public class A { void foo( int i ) throws Exception { if( i != 1 ); { throw new Exception(); } System.out.println( "bar" ); } } Observed behavior: 'System.out.println( "bar" );' causes "Unreachable code" error. Expected behavior: the code should compile w/o any errors.
The error is correct. You have a semicolon as the then clause for the if hence the throws clause always occurs. This makes any statements following unreachable. If you try your code on java compiler it too should and does report the same error.
Thanks Michael to have pointed this :-)
Thanks Michael, the compiler is indeed right. Also note that one can enable an optional compiler warning to detect empty control flow statements like this one (which are usually just mistakes): Preferences>Java>Compiler>Potential programming problems>Empty statement