001 package org.rakeshv.xml.addressbook;
002
003 /**
004 * A custom exception that is used when any kind of exceptions are
005 * encountered when interacting with the JDOM package. Instances of
006 * this exception are also thrown, when implementation specific error
007 * conditions are encountered.
008 *
009 * <p>Copyright 2003 Rakesh Vidyadharan</p>
010 *
011 * @author Rakesh Vidyadharan 2003 March 2
012 * @version $Id: AddressException.java,v 1.2 2004/05/26 11:42:39 rakesh Exp $
013 */
014 public class AddressException extends Exception
015 {
016 /**
017 * A boolean field that indicates the criticality of the error. A
018 * value of <code>true</code> is used to indicate a critical error,
019 * while a value of <code>false</code> is used to indicate a non
020 * critical error.
021 */
022 private boolean critical = true;
023
024 /**
025 * The "friendly" error message that describes the error that was
026 * encountered.
027 */
028 private String message = "";
029
030 /**
031 * The exception that lead to this custom exception being thrown.
032 * This class maintains a reference to the root problem, as it will
033 * be easier to do global actions such as logging the exception in
034 * this class.
035 */
036 private Throwable exception = null;
037
038 /**
039 * Create a new exception with the specified message.
040 *
041 * @param critical - Use a value <code>true</code> to
042 * indicate that the error encountered was critical.
043 * @param message - The message that describes the problem.
044 */
045 public AddressException( boolean critical, String message )
046 {
047 this.critical = critical;
048 this.message = message;
049 }
050
051 /**
052 * Create a new exception with the specified message and instance of
053 * <code>Throwable</code> that caused the problem.
054 *
055 * @param critical - Use a value <code>true</code> to
056 * indicate that the error encountered was critical.
057 * @param message - The message that describes the problem.
058 * @param exception - The exception that caused this
059 * instance of the exception to be thrown.
060 */
061 public AddressException( boolean critical, String message,
062 Throwable exception )
063 {
064 this.critical = critical;
065 this.message = message;
066 this.exception = exception;
067 }
068
069 /**
070 * Over-ridden form of the method inherited from the parent class.
071 * Just return the {@link #message} value.
072 *
073 * @return String - The {@link #message} value.
074 */
075 public String toString()
076 {
077 return message;
078 }
079
080 /**
081 * Return the value/reference of the {@link #exception}.
082 *
083 * @return Throwable - The value/reference of exception.
084 */
085 public final Throwable getException()
086 {
087 return exception;
088 }
089 }