-1

I really don't understand use of finally block... in try-catch block, Whether we use finally or not we can get same run of our code. for example what is difference between these code:

   try
   {
       System.out.println(1/0);
   }
   catch(ArithmeticException e)
   {
       System.out.println("Error");
   }
   finally
   {
       System.out.println("After try-catch");
   }

and this:

   try
   {
       System.out.println(1/0);
   }
   catch(ArithmeticException e)
   {
       System.out.println("Error");
   }

   System.out.println("After try-catch");

what is logically difference in output or hierarchy of running codes???

epoch
  • 16,396
  • 4
  • 43
  • 71
Ahmad Vatani
  • 1,630
  • 4
  • 21
  • 34

1 Answers1

1

A finally will ALWAYS execute, except in certain cases, such as a System.exit() call, or a thread abruptly exiting.

As always the JLS defines all behaviours

epoch
  • 16,396
  • 4
  • 43
  • 71