Coverage Report - org.apache.commons.scaffold.lang.ChainedException
 
Classes in this File Line Coverage Branch Coverage Complexity
ChainedException
0%
0/40
0%
0/14
1.636
 
 1  
 /*
 2  
  * Copyright 2001,2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.scaffold.lang;
 18  
 
 19  
 import org.apache.commons.scaffold.text.ConvertUtils;
 20  
 
 21  
 
 22  
     /**
 23  
      * Mimicks new functionality in 1.4
 24  
      * http://www.javaworld.com/javaworld/jw-08-2001/jw-0803-exceptions.html
 25  
      * @author Brian Geotz
 26  
      * @version $Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $
 27  
      */
 28  
     public class ChainedException extends Exception {
 29  
 
 30  
          private static final String CAUSED_BY = "Caused by: ";
 31  
 
 32  
          private Throwable cause;
 33  
 
 34  
          public ChainedException() {
 35  0
              super();
 36  0
          }
 37  
 
 38  
          public ChainedException(String message) {
 39  0
              super(message);
 40  0
          }
 41  
 
 42  
          public ChainedException(String message, Throwable cause) {
 43  0
              super(message);
 44  0
              this.cause = cause;
 45  0
          }
 46  
 
 47  
          public ChainedException(Throwable cause) {
 48  0
              super();
 49  0
              this.cause = cause;
 50  0
          }
 51  
 
 52  
          public Throwable getCause() {
 53  0
              return this.cause;
 54  
          }
 55  
 
 56  
          public boolean isCause() {
 57  0
              return (this.cause!=null);
 58  
          }
 59  
 
 60  
          public String getCauseMessage() {
 61  0
              if (this.cause==null)
 62  0
                 return null;
 63  0
              return this.cause.getMessage();
 64  
          }
 65  
 
 66  
          public void getMessage(StringBuffer sb) {
 67  0
              sb.append(super.getMessage());
 68  0
              sb.append(ConvertUtils.LINE_FEED);
 69  0
              if (cause != null) {
 70  0
                  sb.append(CAUSED_BY);
 71  0
                  if (cause instanceof ChainedException) {
 72  0
                      ChainedException chainedCause = (ChainedException) cause;
 73  0
                      chainedCause.getMessage(sb);
 74  0
                  }
 75  
                  else {
 76  0
                      sb.append(cause.getMessage());
 77  
                  }
 78  
              }
 79  0
          }
 80  
 
 81  
          public void printStackTrace() {
 82  0
              super.printStackTrace();
 83  0
              if (cause != null) {
 84  0
                  System.err.println(CAUSED_BY);
 85  0
                  cause.printStackTrace();
 86  
              }
 87  0
          }
 88  
 
 89  
          public void printStackTrace(java.io.PrintStream ps) {
 90  0
              super.printStackTrace(ps);
 91  0
              if (cause != null) {
 92  0
                  ps.println(CAUSED_BY);
 93  0
                  cause.printStackTrace(ps);
 94  
              }
 95  0
          }
 96  
 
 97  
          public void printStackTrace(java.io.PrintWriter pw) {
 98  0
              super.printStackTrace(pw);
 99  0
              if (cause != null) {
 100  0
                  pw.println(CAUSED_BY);
 101  0
                  cause.printStackTrace(pw);
 102  
              }
 103  0
          }
 104  
     }
 105