• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we have nested finally block ?

 
raj chopra
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

few parts of my code have too many open connections. so i plan to close them where necessary .

my dialama was that shall i go ahead with nested finally block at each try block respectively or to go with single finally block to close all the connections ?

please guide me to right steps in doing so .

below i present sample code for closing the connections

/
 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and no.
You cannot nest a finally inside another finally. You can however nest a try-finally inside a finally. In Java7, they introduced try with resources so as to obviate the need for such strange syntax.
 
raj chopra
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply .

Campbell Ritchie wrote:Yes and no.
You cannot nest a finally inside another finally. You can however nest a try-finally inside a finally. In Java7, they introduced try with resources so as to obviate the need for such strange syntax.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome

Please only use the quote button if you are commenting about a particular part of the previous post; in that instance you are simply duplicating it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic