aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Error in Answer for Java Quiz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Error in Answer for Java Quiz" Watch "Error in Answer for Java Quiz" New topic
Author

Error in Answer for Java Quiz

Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Hi,
This is to point out what I think is an error in the answer to a question in Javaranch. The answer is the one about if an exception is not caught. You give the answer as something to the effect that the calling method resumes execution.
That is contrary from what I have learned since what is supposed to happen is that if an exception is not explicitly caught and handled at the moment, it percolates upwards in the method activation stack, and is dealt with by the default exception handler if not other handler was "waiting" for that exception.
So in many cases the calling method will never see the light of day and the thread in which the exception occurred will be terminated. What do you think?
Summary: I think that saying that the calling method will resume execution when an exception is not caught is wrong.
Sincerely,
Tony Alicea


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20729
    ∞

I need the exact wording for the question.
Is it: "if an exception is not caught, the finally block will run and then execution will return to the calling method."
??


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Yes, that's the one. Of course, for the question I assumed a sequence like:
<CODE>
try {
}
catch (Exception e) {
}
finally {
}
</CODE>
and that the exception is thrown inside the <CODE>try</CODE> block and not caught in the <CODE>catch</CODE>.
In that case, after the <CODE>finally</CODE> block is done, then the exception should "bubble up" to the next handler, even if it is the "Mother of All Exception Handlers" which spits out <CODE>e.getMessage()</CODE> and stops the thread.
Then again, maybe I am missing something... :-)
Thanks
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20729
    ∞

I think the problem we have here is that the question is ambiguous. Your thinking is correct.
How about this: "if an exception is not caught, the finally block will run and the rest of the method is skipped."
With the answer being TRUE.
Is that clearer? Do you think it is accurate?
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
"What we've got here is failure to communicate."


(From the film Cool Hand Luke (1967))
"How about this:


'if an exception is not caught, the finally block will run and the rest of the method is skipped.'   With the answer being TRUE. Is that clearer?   Do you think it is accurate?
Yes and Yes! Thanks for asking...
Tony
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20729
    ∞

I made the change.
Let me know if you see it and it looks okay. This is the first time I've changed the game.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in Answer for Java Quiz