Java- try catch block example

// Example of Simple try catch block  

import java.util.*;            // for scanner class

class Test

public static void main(String ar[])

int a,b,c;

Scanner scan=new Scanner(;

System.out.println("Enter value of denominator");

try{   // try block where exception can occur

c=a/b;     // here exception can fire  

System.out.println("after devide result= "+c);

}catch(ArithmeticException e)   //to handle exception

System.out.println("please don't divide number by zero");


System.out.println("ok bye!!");  //This line will execute even if there is any  Exception




C:\JAVA>java Test
Enter value of denominator
after devide result= 2
ok bye!!