Coverage Report - org.apache.commons.latka.LatkaException
 
Classes in this File Line Coverage Branch Coverage Complexity
LatkaException
0%
0/32
0%
0/12
1.857
 
 1  
 /*
 2  
  * Copyright 1999-2002,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.latka;
 18  
 
 19  
 import java.io.PrintStream;
 20  
 import java.io.PrintWriter;
 21  
 
 22  
 import org.xml.sax.SAXException;
 23  
 
 24  
 /**
 25  
  * Latka throws this exception to the client whenever a problem
 26  
  * occurs that is not covered by one of the standard JDK exceptions
 27  
  * (validation errors, SAX problems, etc.)
 28  
  *
 29  
  * @author Morgan Delagrange
 30  
  * @author dIon Gillard
 31  
  * @version $Id: LatkaException.java 155424 2005-02-26 13:09:29Z dirkv $
 32  
  */
 33  
 public class LatkaException extends Exception {
 34  
   
 35  
     /**
 36  
      * The original exception
 37  
      */
 38  0
     protected Exception _wrappedException = null;
 39  
 
 40  
     /**
 41  
      * Standard exception constructor
 42  
      * @param message some text explaining the exception
 43  
      */
 44  
     public LatkaException(String message) {
 45  0
         super(message);
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Wrapped exception.
 50  
      *
 51  
      * @param e exception to wrap
 52  
      */
 53  
     public LatkaException(Exception e) {
 54  0
         super(e.toString());
 55  0
         _wrappedException = e;
 56  0
     }
 57  
 
 58  
     /**
 59  
      * Get a wrapped exception
 60  
      *
 61  
      * @return a wrapped exception, or null if no wrapped
 62  
      *         exception exists.
 63  
      */
 64  
     public Exception getException() {
 65  0
         return _wrappedException;
 66  
     }
 67  
 
 68  
     /**
 69  
      * Print a wrapped exception to stdout and, in the case
 70  
      * of SAXExceptions, an additional wrapped exception.
 71  
      * This method does _not_ print the exception's message
 72  
      * itself.
 73  
      *
 74  
      * @param e LatkaException with wrapped messages.
 75  
      */
 76  
     public static void printWrappedExceptions(LatkaException e) {
 77  0
         Exception wrappedException = e.getException();
 78  
 
 79  0
         if (wrappedException != null) {
 80  0
             System.out.println("Wraps exception:");
 81  0
             e.printStackTrace();
 82  
 
 83  0
             if (wrappedException instanceof SAXException) {
 84  0
                 Exception saxWrappedException =
 85  
                   ((SAXException) wrappedException).getException();
 86  0
                 if (saxWrappedException != null) {
 87  0
                     System.out.println("Wraps exception:");
 88  0
                     e.printStackTrace();
 89  
                 }
 90  
             }
 91  
 
 92  
         }
 93  0
     }
 94  
 
 95  
     /**
 96  
      * provide wrapped exception details 
 97  
      */
 98  
     public void printStackTrace() {
 99  0
         if (getException() != null) {
 100  0
             System.err.println("Wrapped Exception details:");
 101  0
             getException().printStackTrace();
 102  
         }
 103  
         
 104  0
         super.printStackTrace();
 105  0
     }
 106  
     
 107  
     /**
 108  
      * provide wrapped exception details 
 109  
      * @param s PrintStream to print to
 110  
      */
 111  
     public void printStackTrace(PrintStream s) {
 112  0
         if (getException() != null) {
 113  0
             s.println("Wrapped Exception details:");
 114  0
             getException().printStackTrace(s);
 115  
         }
 116  
         
 117  0
         super.printStackTrace(s);
 118  0
     }
 119  
     
 120  
     /**
 121  
      * Print wrapped exception details, if any
 122  
      * @param s the print writer to send output to
 123  
      */
 124  
     public void printStackTrace(PrintWriter s) {
 125  0
         if (getException() != null) {
 126  0
             s.println("Wrapped Exception details:");
 127  0
             getException().printStackTrace(s);
 128  
         }
 129  
         
 130  0
         super.printStackTrace(s);
 131  0
     }
 132  
     
 133  
 }