Results 1 to 2 of 2
  1. #1
    vinsun is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default writing Custom exception and its implementation

    Hi all,

    can somebody help me writing a custom exception class
    checkDateException and also how to use that class in PatientDateVerifier where the
    scenario goes like this.............


    Class: CheckDateException
    Description: This class is a checked exception class.


    Constructor: public CheckDateException(GregorianCalendar checkDate,
    String msg)
    Description: Saves checkDate and msg to the class’ instance
    variables.


    Method: public String toString()
    Description: Concatenates the String value of checkDate and msg.


    Class: PatientDateVerifier
    Description: This class will be used to verify a patient’s checkup
    date.


    Constructor: public PatientDateVerifier()
    Description: Creates an instance of the DateValidator class.


    Method: public void verifyCheckUpDate(GregorianCalendar checkUpDate)
    throws CheckDateException
    Description: If checkUpDate is a future date, it throws an exception
    with the
    message: Remarks:\nInvalid date: Check-up date is in the future.


    If checkUpDate is older than six months, it throws an exception
    with the message: Remarks:\nCheck-up date is longer than six
    months.\nPatient needs another checkup.


    If checkUpDate falls in the month of December, it throws an
    exception with the message: Remarks:\nPatient needs smallpox
    vaccination.


    Any help or suggestion is appreciated.


    Thanks and regards

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by vinsun View Post
    Hi all,

    can somebody help me writing a custom exception class
    checkDateException and also how to use that class in PatientDateVerifier
    Writing another checked exception is easy: extend your class from the Exception class; may I sugges you create a general class from which you can extend other, more specific exceptions? Like so:

    Java Code:
    public class YourAppException extends Exception {
    	
    	public YourAppException() {
    		super();
    	}
    
    	public YourAppException(String msg) {
    		super(msg);
    	}
    
    	public YourAppException(Throwable t) {
    		super(t);
    	}
    
    	public YourAppException(String msg, Throwable t) {
    		super(msg, t);
    	}
    }
    Your checkDateException (a bad name b.t.w.) can be a subclass of the class mentioned above. By extending from the Exception class the excpeptions are checked by the compiler.

    kind regards,

    Jos

Similar Threads

  1. [SOLVED] SWT Custom Exception handling
    By shinobu in forum SWT / JFace
    Replies: 2
    Last Post: 04-21-2009, 09:39 AM
  2. FFT implementation (null pointer exception)
    By Jolee in forum Advanced Java
    Replies: 6
    Last Post: 03-08-2009, 04:59 PM
  3. [SOLVED] Writing an Iterator method in a custom list
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 02-12-2009, 05:22 AM
  4. Custom ArraySet implementation
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:41 PM
  5. Custom ArrayMap implementation
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •