This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code following the finally block.

 
keisin syu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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 ]
 
Keen Chen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, I think because in ur code, the exception is a handled exception. it's caught correctly.
 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • 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 ]
 
Levente Szekrenyes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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
  • 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:-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic