Unreachable code Error or Warning?

In Java, unreachable code is treated as compilation error. What do you think? Isn’t making it warning would have made developers’ life simpler?

Of course you can write –

if( true )

What if you could simply write return. This helps in testing a function quickly. As a good programming practice we always remove all warnings from code, and such unconditional return statements can be rectified later.

Tagged on: ,

2 thoughts on “Unreachable code Error or Warning?

  1. Pace

    I agree. Not only would this be more useful for coders wishing to test something, but what if you have a program that autogenerates Java code as its output? Now you have to create a special case for this sort of thing, re-engineering the code validator when the compiler could do the job just as well if this were a warning instead of an error.

  2. Hendrik

    Yes. C# for example treats unreachable code as just a warning. Sometimes this is simply volitional. I need this right now. The only choice I have is commenting out anything after the return. Unreachable code should definitly be only a warning.

Leave a Reply

Your email address will not be published. Required fields are marked *