Coverage Report - net.wotonomy.foundation.NSForwardException
 
Classes in this File Line Coverage Branch Coverage Complexity
NSForwardException
0% 
0% 
2.2
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2000 Michael Powers
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 */
 18  
 
 19  
 package net.wotonomy.foundation;
 20  
 
 21  
 import java.io.PrintStream;
 22  
 import java.io.PrintWriter;
 23  
 import java.io.StringWriter;
 24  
 
 25  
 /**
 26  
 * Serves to wrap an exception inside of a RuntimeException,
 27  
 * which is not required to be declared in a throws statement.
 28  
 *
 29  
 * @author michael@mpowers.net
 30  
 * @author $Author: cgruber $
 31  
 * @version $Revision: 893 $
 32  
 */
 33  
 
 34  
 public class NSForwardException extends RuntimeException
 35  
 {
 36  
         protected String message;
 37  
         protected Throwable wrappedThrowable;
 38  
         
 39  
         /**
 40  
         * Default constructor.
 41  
         */ 
 42  
         public NSForwardException()
 43  
         {
 44  0
                 super();
 45  0
                 message = null;
 46  0
                 wrappedThrowable = null;        
 47  0
         }
 48  
         
 49  
         /**
 50  
         * Standard constructor with message.
 51  
         */
 52  
         public NSForwardException( String aMessage )
 53  
         {
 54  0
                 super( aMessage );
 55  0
                 message = aMessage;
 56  0
                 wrappedThrowable = null;
 57  0
         }
 58  
         
 59  
         /**
 60  
         * Specifies a throwable to wrap.
 61  
         */ 
 62  
         public NSForwardException( Throwable aThrowable )
 63  
         {
 64  0
                 super();
 65  0
                 message = null;
 66  0
                 wrappedThrowable = aThrowable;
 67  0
         }
 68  
         
 69  
         /**
 70  
         * Specifies a message and a throwable to wrap.
 71  
         */ 
 72  
         public NSForwardException( Throwable aThrowable, String aMessage )
 73  
         {
 74  0
                 super( aMessage );
 75  0
                 message = aMessage;
 76  0
                 wrappedThrowable = aThrowable;
 77  0
         }
 78  
     
 79  
     /**
 80  
     * Returns the wrapped throwable.
 81  
     */
 82  
     public Throwable originalException()
 83  
     {
 84  0
         return wrappedThrowable;   
 85  
     }
 86  
         
 87  
         public void printStackTrace(PrintWriter s)
 88  
         {
 89  0
                 if ( message != null )
 90  
                 {
 91  0
                         s.println( toString() );        
 92  
                 }
 93  0
                 if ( wrappedThrowable != null )
 94  
                 {
 95  0
                         wrappedThrowable.printStackTrace( s );
 96  0
                         return;
 97  
                 }
 98  0
                 super.printStackTrace( s );
 99  0
         }
 100  
         
 101  
         public void printStackTrace(PrintStream s)
 102  
         {
 103  0
                 if ( message != null )
 104  
                 {
 105  0
                         s.println( toString() );        
 106  
                 }
 107  0
                 if ( wrappedThrowable != null )
 108  
                 {
 109  0
                         wrappedThrowable.printStackTrace( s );        
 110  0
                         return;
 111  
                 }
 112  0
                 super.printStackTrace( s );
 113  0
         }
 114  
         
 115  
         public void printStackTrace()
 116  
         {
 117  0
                 if ( message != null )
 118  
                 {
 119  0
                         System.err.println( toString() );        
 120  
                 }
 121  0
                 if ( wrappedThrowable != null )
 122  
                 {
 123  0
                         wrappedThrowable.printStackTrace();        
 124  0
                         return;
 125  
                 }
 126  0
                 super.printStackTrace();
 127  0
         }
 128  
     
 129  
     public String stackTrace()
 130  
     {
 131  0
         StringWriter writer = new StringWriter();
 132  0
         PrintWriter printWriter = new PrintWriter( writer );
 133  0
                 if ( wrappedThrowable != null )
 134  
                 {
 135  0
                         wrappedThrowable.printStackTrace( printWriter );        
 136  0
                 }
 137  
         else
 138  
         {
 139  0
                     super.printStackTrace( printWriter );
 140  
         }
 141  0
         printWriter.flush();
 142  0
         printWriter.close();
 143  0
         return writer.toString();
 144  
     }
 145  
 
 146  
         public String toString()
 147  
     {
 148  0
         String result = message;
 149  0
         if ( result == null ) result = "";
 150  0
                 if ( wrappedThrowable != null )
 151  
                 {
 152  0
             result = wrappedThrowable.toString() + " : " + result;
 153  
                 }
 154  0
         return result;
 155  
     }
 156  
     
 157  
 }