Unreachable finally

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

Moderator: admin

Post Reply
crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Unreachable finally

Post by crazymind »

Code: Select all

try {
  for( ;; );
}finally { }
This finally block will not get execute?

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

Re: About Question enthuware.ocajp.i.v8.2.1025 :

Post by admin »

I am not sure what is your question. If you are asking whether it will cause unreachable error, then no. Compiler does not know that the loop is an infinite loop.
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1025 :

Post by crazymind »

admin wrote:
Thu Jan 10, 2019 11:57 pm
I am not sure what is your question. If you are asking whether it will cause unreachable error, then no. Compiler does not know that the loop is an infinite loop.
The only times finally won't be called are:

If you invoke System.exit();
If the JVM crashes first;
If the JVM reaches an infinite loop (or some other non-interruptable, non-terminating statement) in the try or catch block;
If the OS forcibly terminates the JVM process; e.g. "kill -9 " on UNIX.
If the host system dies; e.g. power failure, hardware error, OS panic, etcetera.
If finally block is going to be executed by daemon thread and all other non daemon threads exit before finally is called.
Is this true? Thanks

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

Re: About Question enthuware.ocajp.i.v8.2.1025 :

Post by admin »

Where did you see this list?
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1025 :

Post by crazymind »

admin wrote:
Fri Jan 11, 2019 12:40 am
Where did you see this list?
Hi, it is on stackoverflow.
https://stackoverflow.com/questions/650 ... ed-in-java

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

Re: Unreachable finally

Post by admin »

We sent you an email to your email account that you used to register on this forum regarding an important administrative matter. Please check it.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests