• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Aquestion from the test #132

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Mike. I think so.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic