Results 1 to 2 of 2
- 07-02-2010, 09:49 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 1
- Rep Power
- 0
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
- 07-02-2010, 10:24 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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:
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.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); } }
kind regards,
Jos
Similar Threads
-
[SOLVED] SWT Custom Exception handling
By shinobu in forum SWT / JFaceReplies: 2Last Post: 04-21-2009, 09:39 AM -
FFT implementation (null pointer exception)
By Jolee in forum Advanced JavaReplies: 6Last Post: 03-08-2009, 04:59 PM -
[SOLVED] Writing an Iterator method in a custom list
By xcallmejudasx in forum New To JavaReplies: 2Last Post: 02-12-2009, 05:22 AM -
Custom ArraySet implementation
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:41 PM -
Custom ArrayMap implementation
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:40 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks