• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finally block vs normal-out-of-try-catch-scope

 
Ian Cabigon
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'd like to know what is the difference with the following try-catch and try-catch-finally snippets.
Enlighten me please.



Thanks,
Ian
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If c() is in a finally block, it is executed even if b() throws an exception, or a() throws something that doesn't match the catch block. Without the finally, c() wouldn't execute if either of those things happened.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest Friedman-Hill
 
Ian Cabigon
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I finally got it.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:If c() is in a finally block, it is executed even if b() throws an exception, or a() throws something that doesn't match the catch block. Without the finally, c() wouldn't execute if either of those things happened.


additionally, if try has any return statement, then c() without finally fails to execute
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic