Hi : All ! I have a question about exception execute ! Question 16: What appears in the standard output if the method named problem() in the code below throws an instance of class Exception when the method named trythis() is invoked?
Select all valid answers. a) "1" b) "2" c) "3" d) "4" e) "5" tha answer is a,c,d . But I think e)also should be print ! I know that when there is some exception cannot be catched , finally block will execute and after finally will never execute! Now , I think this should excute because no exception cannot be catched. Can anyone tell me mine is wrong or right ? (Marilyn added code tags)
[This message has been edited by Marilyn deQueiroz (edited November 04, 2001).]
Hi, The finally block executes no matter what (except when there is a System.exit call before a call to the finally block). The catch block executes only if an exception is thrown. In your case, if an instance of class exception is thrown, the try catch block dealing with that particular exception gets executed and the finally block is run after that. The statement after the finally block is not executed because there is a return statement in the catch block that dealt with the exception. What I have said here is the very tip of the iceberg regarding exception handling. There are a great deal of permutations and combinations to deal with. You may want to take this as a start and explore further. Writing code snippets and learning from the compiler is the way I would recommend. Hope this helps Shyam