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 ]
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 ]
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...
Joined: Dec 04, 2002
thank you all. it looks like i'm not reading the quote carefully and get lost when i try my code:-)