This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Could anyone please explain why 5 is getting printed here? I thought when an exception occurs, control is transferred to the respective catch clause and then finally gets executed. After this, the program exits. Please correct me if I am wrong. Thanks!
1)When Exception is caught ctrl goes to finally block(if their is any), and normal execution continues after finally block(as if Exception as not occured). 2)Think! When Exception is caught and handled, What is the necessary to exit.
3)If Exception is not caught then finally block is executed and remaining code after finally block is skipped, -->ctrl goes to calling method. 4)If you do not catch & handle Exception even there -->ctrl goes to its calling method...continues till you catch Exception. [ May 12, 2006: Message edited by: Girish Nagaraj ]
when an Exception is caught, the respective exception is executed and the finally block is excecuted and the programme continues from there...untill it reaches the stack....that is why we use Exception mechanism.