Wednesday, 10 July 2013

Exception - Try Catch

ASSIGNMENT 4: EXCEPTION, TRY-CATCH:

public class MyJavaProject {
   


    public static void main(String[] args) {
        int a = 4;
        int b = 0;
        int x = a / b;
        try
        {
            System.out.println("your value is divided");
            System.out.println(x);
        }
        catch(ArithmeticException ex)
        {
            System.out.println("You can't this value by zero");
        }
        // first priority is given to try, if it is possible to calculate. Otherwise an error will be caught.

}

No comments:

Post a Comment