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

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

Moderator: admin

Post Reply
__Bill
Posts: 25
Joined: Thu Mar 27, 2014 11:35 am
Contact:

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

Post by __Bill »

admin wrote:Not sure what is your point.
My only point is understanding what is going on. I asked why if there's a return in finally is a return elsewhere not unreachable code. You said the return in the try is evaluated and to try a print statement to show it. I tried that but it tells me it's unreachable code.

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

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

Post by admin »

Your original question was, "If finally has a return, why isn't the return in try and the return in catch unreachable code?" For that, I said a return is try is executed even if there is a return in finally.

I didn't say return in try is always reachable! Return is not a special statement in this respect. Just like any other piece of code, there could be a million examples where return in try is unreachable. But they have nothing to do with having a return in finally!
In your new example, the return in try is unreachable because of the throw statement. Its unreachability has no relation to the return in finally, which is what I was referring to earlier.
If you like our products and services, please help us by posting your review here.

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

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

Post by AndaRO »

TRY block is not executed.

Why danail said that "TRY block is executed"?

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post by OCAJO1 »

Since there is no code after the finally block, there is no unreachable error raised.

Given the above statement, can one conclude that (at least on this exam), if there is no more code after a try/catch/finally block with return; in every block, the question is not focused on unreachable code error?

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

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

Post by admin »

Yes, that sounds correct but as I mentioned to you earlier, it is not possible to answer your query with 100% certainty because it is too vague. I may not be able to think of a case where this doesn't hold true at this moment but someone else may. So, if there is no code associated with your situation, the answer can only be speculative.
I would not suggest you to form such rules in your head. Instead, focus on analyzing the given code on a case by case basis.
If you like our products and services, please help us by posting your review here.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post by OCAJO1 »

Of course you are correct. I think the reason my reasoning has become somewhat warped for the questions on the tests, is like passing the DMV written test which is for driving in a lab not reality of the road, I'm trying to rethink how to assess a questions on the real exam :geek:

Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests