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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
zhengye1
Posts: 17
Joined: Wed Jan 07, 2015 12:06 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest