Is there a way to ignore the 'Unreachable statement' error?

No. It's a compile time error. So you must get rid of it before running your class.

What I usually do is put a fake if statement in front of it. Something like:

if(true)
    return;
// unwanted code follows. no errors.
i++;
j++;

With this code, you will not get a Unreachable statement error. And you will get what you want.


33. if (1==1) return;
34. System.out.println("Hello world!");

It works in other languages too. But ByteCode without row 34.


If you want disable/enable certain piece of code many times trick from old C may help you:

some_code();
more_code();
// */

/*
some_code();
more_code();
// */

Now you need only to write /* at the beginning


It isn't possible to ignore this error since it is an error according to the Java Language Specification.

You might also want to look at this post: Unreachable code error vs. dead code warning in Java under Eclipse?

Tags:

Java