Tuesday, 23 September 2014

Write a JAVA program to implement a Queue using user defined Exception Handling (also make use of throw, throws)

import java.io.*;
class myException extends Exception
{ myException()
  { System.out.println("Error:Password too short");
  }
  myException(int n)
  { System.out.println("Error:Only adults can join");
  }
}
class user_exception
{ public static void main(String s[])throws IOException,myException


  { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    try
    { System.out.print("Enter user name : ");
      String n=br.readLine();
      System.out.print("Enter your password : ");
      String m=br.readLine();
      if(m.length() <6)
        throw new myException();
      System.out.print("Enter your age : ");
      int o=Integer.parseInt(br.readLine());
      if(o<18)
        throw new myException(o);
    }
    catch(Exception e)
    {    }
  }
}  
output:


0 comments:

Post a Comment