Consider the following program:
public class Main { public static void main(String []args) { try { int i = 10/0; // LINE A System.out.print("after throw -> "); } catch(ArithmeticException ae) { System.out.print("in catch -> "); return; } finally { System.out.print("in finally -> "); }//w ww .j a v a2 s . co m System.out.print("after everything"); } }
Which one of the following options best describes the behavior of this program?
e)
The statement println("after throw -> "); will never be executed since the line marked with the comment LINE A throws an exception.
The catch handles ArithmeticException, so println("in catch -> "); will be executed.
Following that, there is a return statement, so the function returns.
But before the function returns, the finally statement should be called, hence the statement println("in finally -> "); will get executed.
So, the statement println("after everything"); will never get executed.