• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

finally in try/catch Mock exam

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#132 if an exception is not caught the finally block will run and the rest of the method is skipped
Answer:True
I think the answer is False or it should have been if exception is caught.
I am confused.
This question is from Javaranch mock exam
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sadeep,
The answer is true. Remember that the finally block always gets executed, no matter what. This will allow the programmers to do cleanup and freeup resources in one place which is guaranteed to execute.
Look at the following code for better understanding.

Also note that the only statement that can cause finally to be skipped is the forced System.exit() call.
Hope this helps,
Ajith
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should the question be modified to ask "if a RUNTIME exception is not caught the finally block will run...?" If a non-runtime exception is not caught, the compiler will complain about it before runtime.
 
Everybody's invited. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic