Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javatools/util/CommonRuntimeException.java


1   /*
2       Javatools (modified version) - Some useful general classes.
3       Copyright (C) 2002-2003  Chris Bitmead (original) Antonio Petrelli (modified)
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program 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
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  
19      Contact me at: brenmcguire@users.sourceforge.net
20   */
21  package javatools.util;
22  import java.io.*;
23  
24  /**
25   * A base class for other types of Runtime exceptions.
26   * @author Chris Bitmead
27   * @version 0.7
28   * @commentedby Antonio Petrelli
29   */
30  public class CommonRuntimeException extends RuntimeException {
31      /** The exception to use.
32       */    
33    Throwable nextException;
34  
35          /** Creates a new CommonRuntimeException.
36           * @param mesg The message.
37           */        
38    public CommonRuntimeException(String mesg) {
39      super(mesg);
40    }
41          /** Creates a new CommonRuntimeException.
42           * @param mesg The message.
43           * @param exception The base exception.
44           */        
45    public CommonRuntimeException(String mesg, Throwable exception) {
46      super(mesg);
47      nextException = exception;
48    }
49          /** Creates a new CommonRuntimeException.
50           * @param exception The base exception.
51           */        
52    public CommonRuntimeException(Throwable exception) {
53      nextException = exception;
54    }
55          /** Returns the next exception.
56           * @return The next exception.
57           */        
58    public Throwable getNextException() {
59      return nextException;
60    }
61          /** Returns a string representing this exception.
62           * @return The string representing this exception.
63           */        
64    public String toString() {
65      String rtn = super.toString();
66      if (nextException != null) {
67        rtn += nextException.toString();
68      }
69      return rtn;
70    }
71          /** Returns the stack trace.
72           * @return The string representing the stack trace.
73           */        
74    public StackTraceElement[] getStackTrace() {
75  /*    ByteArrayOutputStream baos = new ByteArrayOutputStream();
76      printStackTrace(new PrintStream(baos));
77      if (nextException != null) {
78        nextException.printStackTrace(new PrintStream(baos));
79      }
80      return baos.toString();
81   */
82              return super.getStackTrace();
83    }
84          /** Prints the stack trace to a print writer.
85           * @param s The print writer to use.
86           */        
87    public void printStackTrace(PrintWriter s) {
88      super.printStackTrace(s);
89      if (nextException != null) {
90        nextException.printStackTrace( s);
91      }
92    }
93          /** Prints stack trace to standard output.
94           */        
95    public void printStackTrace() {
96      super.printStackTrace();
97      if (nextException != null) {
98        nextException.printStackTrace();
99      }
100   }
101         /** Prints stack trace to a print stream.
102          * @param s The print stream to use.
103          */        
104   public void printStackTrace(PrintStream s) {
105     super.printStackTrace(s);
106     if (nextException != null) {
107       nextException.printStackTrace( s);
108     }
109   }
110 }