Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1094 :

Posted: Wed Nov 23, 2016 10:24 am
by zhengye1
I thought it is compiling error due to final block will become unreachable code, but seems like not that case...

How does the compiler know there is/are unreachable code(s) or not?

Re: About Question enthuware.ocajp.i.v7.2.1094 :

Posted: Wed Nov 23, 2016 10:33 pm
by admin
It is not possible to explain the whole concept of unreachable code in a post but the main thing is that the compiler cannot execute any code. It makes inferences only based on the existing code and decides whether some part of code is unreachable or not. Here, compiler cannot know what system.exit() does. You, as a programmer know that the JVM will exit but the compiler has no idea. For the compiler, it is just a method call. So it cannot make out that the finally block will never be executed. Here are a few links that you can go through:

http://stackoverflow.com/questions/9276 ... iler-error
https://coderanch.com/t/406677/java/unreachable-code
HTH,
Paul