• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

code following the finally block.

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had met a statement about try, catch and finally block in the pages"code after finally block"(name is add by myself).
here is quote from the page:


If an exception is thrown, then the rest of the code in the try block is not executed. If any catch block matches the exceptions class or a super class of the exception, that block executes. If the exception is not caught correctly, then after the finally block executes, the rest of the code in the method is not executed.


and i don't understand the last sentance and do some test with the code here.
and the code after finally block is executed to print out "after finally".

am i misunderstanding the meaning or is it wrong the statement of the last sentence?
[ December 12, 2002: Message edited by: keisin syu ]
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI, I think because in ur code, the exception is a handled exception. it's caught correctly.
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If the exception is not caught correctly, then after the finally block executes, the rest of the code in the method is not executed.


your code catches the exception, so the rest of the method body is executed after the finally block and the method doesn't terminate or populate the exception to the caller.
[ December 12, 2002: Message edited by: Alfred Kemety ]
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keen is right, your exception is handled correctly, that's why the text "after finally" prints out. If you modify your code like this:

you will notice that your exception is not properly caught, so when run, the program prints out:
"before exception"
"333"
and then just exits with an error messsage, without printing "after finally".
Note that, because the exception wasn't properly caught, I also had to declare that the main method might throw an Exception...
 
keisin syu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you all.
it looks like i'm not reading the quote carefully and get lost when i try my code:-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic