Lab 24
AIM: Write a program in Java to develop user defined exception for ‘Divide by Zero’ error.

DivideByZeroException.java
class MyException extends Exception
{
    private int ex;
    MyException(int b)
    {
        ex=b;
    }
    public String toString()
    {
        return "My Exception :  Number is not divided by "+ex;
    }
}
class DivideByZeroException 
{
    static void divide(int a,int b) throws MyException
    {
        if(b<=0)
        {
            throw new MyException(b);
        }
        else
        {
            System.out.println("Division : "+a/b);
        }
    }
    public static void main(String arg[])
    {
        try
        {
            divide(10,0);
        }
        catch(MyException me)
        {
            System.out.println(me);     
        }
    }
}

Output 
 ‘Divide by Zero’ error.
‘Divide by Zero’ error in java by practical server

Happy Coding :)