Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

finally block may not contain try catch

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic