Turn Desktop View Off
by Dinesh Thakur

Java.lang.Exception Class is the superclass for all exceptions in Java. To creating our own extensions, we simply extend this class.

          class StringTooLarge extends Exception

         {
                       String s;
                       StringTooLarge(String h)
                       {
                            s=h;
                        }
                                public String toString()
                                    {
                                       return "String is Too Large Exception";
                                    }
         }
                public class OwnExceptionJavaExample
                  {
                           public void disp(String k)
                                 {
                                     int n;
                                     try
                                       {
                                          n = k.length();
                                          if(n>10)
                                          throw new StringTooLarge(k);
                                           System.out.println("String is : "+k);
                                        }
                                                catch(StringTooLarge e)
                                                {
                                                   System.out.println("Caught : "+e);
                                           }
                                 } 
                                       public static void main(String args[])
                                    {
                                       OwnExceptionJavaExample OE = new OwnExceptionJavaExample();
                                       OE.disp("India");
                                       OE.disp("ecomputernotes.com");
                                    }
                  }  

Own Exception