• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

finally block may not contain try catch

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


#157 Which of the following statements are true?

(1) A call to a method that throws an exception must always be enclosed in a try/catch block
(2) variables created within a try or catch block will be local to that block
(3) A try statement must always be matched with a catch statement
(4) A finally block may not contain try/catch statements



(4) A finally block may not contain try/catch statements

I chose option 2 only.
Answer says 4 too.

Source: "Giri Mandarika" (Link available in JavaRanch)

Please suggest!

Regards,
cmbhatt
[ April 21, 2007: Message edited by: Chandra Bhatt ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is wrong - I use try/catch in finally blocks all the time, especially when cleaning up network connections, closing OutputStreams and the like (many cleanup methods can throw IOExceptions).
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew,

The matter of confusion was "may not contain try catch block".
One can interpret it like, finally block does not necessarily require try catch block. I mean it is not must to stuff try catch block in the finally clause.

"finally block can include try catch but may not include also" : "My interpretation"

What do you say?



Regards,
cmbhatt
 
Andrew Ebling
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree there is some ambiguity, but I think most people would read the option as "try/catch blocks are not allowed in finally blocks".
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic