*
The moose likes Beginning Java and the fly likes Aquestion from the test #132 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Aquestion from the test #132" Watch "Aquestion from the test #132" New topic
Author

Aquestion from the test #132

Ming Sun
Greenhorn

Joined: Jun 03, 2001
Posts: 2
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

Joined: Feb 20, 2001
Posts: 3695

I think this proves that the answer is FALSE, unless i'm wrong.
Ming Sun
Greenhorn

Joined: Jun 03, 2001
Posts: 2
Thanks, Mike. I think so.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
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

Joined: Sep 29, 2000
Posts: 8521
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)


"JavaRanch, where the deer and the Certified play" - David O'Meara
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Aquestion from the test #132