Page 1 of 1

Unreachable finally

Posted: Thu Jan 10, 2019 4:34 pm
by crazymind

Code: Select all

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

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

Posted: Thu Jan 10, 2019 11:57 pm
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.

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

Posted: Fri Jan 11, 2019 12:20 am
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

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

Posted: Fri Jan 11, 2019 12:40 am
by admin
Where did you see this list?

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

Posted: Fri Jan 11, 2019 9:52 am
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

Re: Unreachable finally

Posted: Fri Jan 11, 2019 9:59 am
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.