luetzkendorf    2005/05/27 10:18:49

  Modified:    src/share/org/apache/slide/common SlideException.java
  Log:
  new methods initCause and getCause to allow chaning of exception
  (patch by Thomas Bellembois)
  
  Revision  Changes    Path
  1.11      +30 -9     
jakarta-slide/src/share/org/apache/slide/common/SlideException.java
  
  Index: SlideException.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/common/SlideException.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SlideException.java       28 Jul 2004 09:38:11 -0000      1.10
  +++ SlideException.java       27 May 2005 17:18:49 -0000      1.11
  @@ -41,6 +41,7 @@
       private static final int DEBUG = Logger.DEBUG;
       private static Logger LOGGER = Domain.getLogger();
   
  +    private Throwable cause = this;
   
       // ----------------------------------------------------------- 
Constructors
   
  @@ -67,11 +68,31 @@
               Domain.warn(message);
           }
   
  -      if (LOGGER.isEnabled(CHANNEL, DEBUG)) {
  -            StringWriter sw = new StringWriter();
  -            printStackTrace( new PrintWriter(sw, true) ); //autoFlush=true
  -            LOGGER.log( sw.toString(), CHANNEL, DEBUG );
  -      }
  +         if (LOGGER.isEnabled(CHANNEL, DEBUG)) {
  +             StringWriter sw = new StringWriter();
  +             printStackTrace( new PrintWriter(sw, true) ); //autoFlush=true
  +             LOGGER.log( sw.toString(), CHANNEL, DEBUG );
  +         }
  +    }
  +    
  +    /**
  +     * Set the cause of the exception
  +     */
  +    public Throwable initCause(Throwable cause) {
  +        if (this.cause != this)
  +            throw new IllegalStateException("Can't overwrite cause");
  +        if (cause == this)
  +            throw new IllegalArgumentException("Self-causation not 
permitted");
  +        this.cause = cause;
  +        return this;
  +    }
  +
  +    
  +    /**
  +     * Get the cause of the exception
  +     */
  +    public Throwable getCause() {
  +        return (cause==this ? null : cause);
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to