Ads

Thursday, 9 November 2017

User-defined Exception program in Java

User-defined Exception




--> User defined exception is nothing but an exception which is created by the user.


Example of user-defined exception in Java


File-1 : - "Invalid.Java"

class Invalid extends Exception
{
   public Invalid(String s)
   {
      Super(s);
   }
}


File-2 :- "JX.java"

 
class JX
{
     public m() throws Invalid
     {
         System.out.println("Java Xpert");
     }
     public static void main(String args[])
     {
    
          try
          {
                 m();
          }
          catch(Invalid e)  
          {
             System.out.println("Hello, This is JavaXpert");
          }
    }
}


sorry for being late....
Post a Comment

Click Here