001    package biz.wedoit4u;
002    
003    /**
004     * A custom exception that is used when any kind of exceptions are
005     * encountered in the CMA application.  Typically exceptions are
006     * encountered while interacting with the database via the entity
007     * beans.
008     *
009     * <p>Copyright 2003 Rakesh Vidyadharan</p>
010     *
011     * @author Rakesh Vidyadharan 01<sup><small>st</small></sup> October 2003
012     * @version $Id: CMAException.java,v 1.4 2004/05/26 11:42:30 rakesh Exp $
013     */
014    public class CMAException 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.  The default value is <code>true</code>.
021       */
022      private boolean critical = true;
023    
024      /**
025       * Create a new exception with the specified message.  Simply
026       * invokes the super class constructor with the message specified.
027       *
028       * @param message - The message that describes the problem.
029       */
030      public CMAException( String message )
031      {
032        super( message );
033        Logger.error( message );
034      }
035    
036      /**
037       * Create a new exception with the specified message.  Simply
038       * invokes {@link #CMAException( String )}, and set the 
039       * value of {@link #critical} with the specified value.
040       *
041       * @param critical - Indicates whether the exception is 
042       *   critical in nature or not.  Value of <code>true</code> indicates
043       *   a critical failure.
044       * @param message - The message that describes the problem.
045       */
046      public CMAException( boolean critical, String message )
047      {
048        this( message );
049        this.critical = critical;
050      }
051    
052      /**
053       * Create a new exception with the specified instance of Throwable.  
054       * Simply invokes the super class constructor with with throwable
055       * specified.
056       *
057       * @param throwable - The instance of Throwable that is
058       *   the cause for this instance of the Exception.
059       */
060      public CMAException( Throwable throwable )
061      {
062        super( throwable );
063        Logger.error( "Exception caught.", throwable );
064      }
065    
066      /**
067       * Create a new exception with the specified instance of Throwable
068       * and a flag indicating whether the exception is critical in nature
069       * or not.  Simply invokes {@link #CMAException( Throwable )}, and 
070       * set the value of {@link #critical} with the value specified.
071       *
072       * @param critical - Indicates whether the exception is 
073       *   critical in nature or not.  Value of <code>true</code> indicates
074       *   a critical failure.
075       * @param throwable - The instance of Throwable that is
076       *   the cause for this instance of the Exception.
077       */
078      public CMAException( boolean critical, Throwable throwable )
079      {
080        this( throwable );
081        this.critical = critical;
082      }
083    
084      /**
085       * Create a new exception with the specified message.  Simply
086       * invokes the super class constructor with the message specified.
087       *
088       * @param message - The message that describes the problem.
089       */
090      public CMAException( String message, Throwable throwable )
091      {
092        super( message, throwable );
093        Logger.error( message, throwable );
094      }
095    
096      /**
097       * Create a new exception with the specified message and instance of
098       * <code>Throwable</code> that caused the problem.  Invokes the
099       * {@link #CMAException( String, Throwable )} constructor, and sets 
100       * the value of {@link #critical} with the value specified.
101       *
102       * @param critical - Indicates whether the exception is 
103       *   critical in nature or not.  Value of <code>true</code> indicates
104       *   a critical failure.
105       * @param message - The message that describes the problem.
106       * @param throwable - The instance of Throwable that caused 
107       *   this instance of the exception to be thrown.
108       */
109      public CMAException( boolean critical, String message, 
110          Throwable throwable )
111      {
112        this( message, throwable );
113        this.critical = critical;
114      }
115      
116      /**
117       * Returns {@link #critical}.
118       *
119       * @return boolean - The value/reference of/to critical.
120       */
121      public final boolean getCritical()
122      {
123        return critical;
124      }
125    }