I am fairly new to Java and unable to understand the flow of control in try-catch-finally blocks. Whenever a exception is caught in a catch block, the code after the catch block is also executed, whether I place it in a finally block or not. Then what is the use of finally block?
class Excp
{
public static void main(String args[])
{
int a,b,c;
try
{
a=0;
b=10;
c=b/a;
System.out.println("This line will not be executed");
}
catch(ArithmeticException e)
{
System.out.println("Divided by zero");
}
System.out.println("After exception is handled");
}
}
There is no difference if I place the last print statement inside the finally block.