Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

finally in try/catch Mock exam

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Grow a forest with seedballs and this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic