Coverage Report - net.wotonomy.foundation.internal.WotonomyException
 
Classes in this File Line Coverage Branch Coverage Complexity
WotonomyException
0% 
0% 
2.125
 
 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.internal;
 20  
 
 21  
 import java.io.PrintStream;
 22  
 import java.io.PrintWriter;
 23  
 
 24  
 /**
 25  
 * This is a simple RuntimeException that can encapsulate
 26  
 * another throwable.  Behaves as a normal RuntimeException
 27  
 * except that it prints a stack trace of the wrapped 
 28  
 * throwable if one is specified.
 29  
 *
 30  
 * Intended to be used anytime you'd 
 31  
 * report an exception with System.out.println: that is,
 32  
 * for debugging and non-user-visible exceptions.
 33  
 *
 34  
 * @author michael@mpowers.net
 35  
 * @author $Author: cgruber $
 36  
 * @version $Revision: 893 $
 37  
 */
 38  
 
 39  
 public class WotonomyException extends RuntimeException
 40  
 {
 41  
         protected String message;
 42  
         protected Throwable wrappedThrowable;
 43  
         
 44  
         /**
 45  
         * Default constructor.
 46  
         */ 
 47  
         public WotonomyException()
 48  
         {
 49  0
                 super();
 50  0
                 message = null;
 51  0
                 wrappedThrowable = null;        
 52  0
         }
 53  
         
 54  
         /**
 55  
         * Standard constructor with message.
 56  
         */
 57  
         public WotonomyException( String aMessage )
 58  
         {
 59  0
                 super( aMessage );
 60  0
                 message = aMessage;
 61  0
                 wrappedThrowable = null;
 62  0
         }
 63  
         
 64  
         /**
 65  
         * Specifies a throwable to wrap.
 66  
         */ 
 67  
         public WotonomyException( Throwable aThrowable )
 68  
         {
 69  0
                 super();
 70  0
                 message = null;
 71  0
                 wrappedThrowable = aThrowable;
 72  0
         }
 73  
         
 74  
         /**
 75  
         * Specifies a message and a throwable to wrap.
 76  
         */ 
 77  
         public WotonomyException( String aMessage, Throwable aThrowable )
 78  
         {
 79  0
                 super( aMessage );
 80  0
                 message = aMessage;
 81  0
                 wrappedThrowable = aThrowable;
 82  0
         }
 83  
     
 84  
     /**
 85  
     * Returns the wrapped throwable.
 86  
     */
 87  
     public Throwable getWrappedThrowable()
 88  
     {
 89  0
         return wrappedThrowable;   
 90  
     }
 91  
         
 92  
         public void printStackTrace(PrintWriter s)
 93  
         {
 94  0
                 if ( message != null )
 95  
                 {
 96  0
                         s.println( "Exception: " + message );        
 97  
                 }
 98  0
                 if ( wrappedThrowable != null )
 99  
                 {
 100  0
                         wrappedThrowable.printStackTrace( s );
 101  0
                         return;
 102  
                 }
 103  0
                 super.printStackTrace( s );
 104  0
         }
 105  
         
 106  
         public void printStackTrace(PrintStream s)
 107  
         {
 108  0
                 if ( message != null )
 109  
                 {
 110  0
                         s.println( "Exception: " + message );        
 111  
                 }
 112  0
                 if ( wrappedThrowable != null )
 113  
                 {
 114  0
                         wrappedThrowable.printStackTrace( s );        
 115  0
                         return;
 116  
                 }
 117  0
                 super.printStackTrace( s );
 118  0
         }
 119  
         
 120  
         public void printStackTrace()
 121  
         {
 122  0
                 if ( message != null )
 123  
                 {
 124  0
                         System.err.println( "Exception: " + message );        
 125  
                 }
 126  0
                 if ( wrappedThrowable != null )
 127  
                 {
 128  0
                         wrappedThrowable.printStackTrace();        
 129  0
                         return;
 130  
                 }
 131  0
                 super.printStackTrace();
 132  0
         }
 133  
         
 134  
 }