This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aquestion from the test #132

 
Ming Sun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who can tell me the reason?
question NO.:#132
question:
if an exception is not caught the finally block will rnn and the rest of method is skipped.
the answer is TRUE.
my question: why skip the rest of method since not catch an exception?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this proves that the answer is FALSE, unless i'm wrong.
 
Ming Sun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Mike. I think so.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
You are actually catching the exception. If you did not have the catch for ArrayIndexOutOfBounds, the method would execute the finally and not do anymore in that method.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike, you didn't HAVE an exception. The question is saying the if you have an exception, and that exception is not caught by a catch block, then the control immediately passes to finally and the rest of the commands after the exception are not executed. This is true.
Try this:

The ArithmeticException is not caught. The output is:
in finally
(Bunch of exception messages complaining about dividing by zero)
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I love english.

I knew all of that, but how I interpreted the question was: "If you have a try-catch-finally, and no exception occurs (an exception is not caught), then what happens."

But of course, duh, they are talking about "uncaught exceptions". The exception DOES occur, but your catch is either not the same, or a superclass of that exception type... in this case yes, the finally occurs and the method returns.

This kind of thing makes me frightened of going to write my Java Certification. It was a simple matter of the phrase "uncaught exception" (which I would have got immediately) versus "an exception is not caught" (which in *my* brain means "there is no exception *to be* caught". Further proof that everyone thinks differently. I really should have seen that.

Hopefully Ming will be back to see the real answer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic