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 wrote:Not sure what is your point.
About Question enthuware.ocajp.i.v7.2.950 :
Moderator: admin
-
- Posts: 25
- Joined: Thu Mar 27, 2014 11:35 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.950 :
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.950 :
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.
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.
-
- Posts: 31
- Joined: Wed Feb 08, 2017 5:42 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.950 :
TRY block is not executed.
Why danail said that "TRY block is executed"?
Why danail said that "TRY block is executed"?
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.950 :
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?
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?
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.950 :
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.
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.
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.950 :
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
Who is online
Users browsing this forum: No registered users and 50 guests