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: Design a JAVA program to demonstrate user defined exception.

