You are on page 1of 2

Practical No 18

class DemoArithmatic //create a class with DemoArithmatic name

public static void main(String args[]) //creating main method

int a=12, b=2, c=2, x, y ;

System.out.println("A="+a);

System.out.println("B="+b);

System.out.println("C="+c);

try //try block

x=a/(b-c); //(12/(2-2) ie 12/0 which is math error

System.out.println("x="+x);

catch(Exception e) //catch block to catch exception

System.out.println("Math exception:"+e); //e contain exception name

finally //finally block

System.out.println("Inside finally block");

y=a/(b+c);

System.out.println("y="+y);

}
Output

You might also like