Wednesday, June 2, 2021

Design a JAVA program to demonstrate user defined exception.

PROGRAM :

package com.company;

class MyException extends Exception

{

    public MyException(String s)

    {

        super(s);

    }

}

 

public class UserDefined

{

    public static void main(String[] args)

    {

        try

        {

            throw new MyException("GeeksGeeks");

        }

        catch (MyException ex)

        {

            System.out.println("Caught");

            System.out.println(ex.getMessage());

        }

    }

}

OUTPUT :



Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home