Monday, 13 February 2017

UnCheckedException : IllegalArgumentExcept



public class IllegalArgumentExcept {

    public static void main(String[] args)
    {
        try {
            IllegalArgumentExcept i1 = new IllegalArgumentExcept();            i1.calculateFactorial(-9);        }catch (IllegalArgumentException ie)
        {
            System.out.println(" Illegal argument");            ie.printStackTrace();        }
    }

    public void calculateFactorial(int n) {
        if (n < 0)
        { throw new IllegalArgumentException("n must be positive");}
        if (n >= 60)
        {   throw new IllegalArgumentException("n must be < 60");}
    }
}

No comments:

Post a Comment