View Javadoc

1   /*
2   This file is part of the xframe software package
3   hosted at http://xframe.sourceforge.net
4   
5   Copyright (c) 2003 Kurt Riede.
6   
7   This library is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Lesser General Public
9   License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11  
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16  
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21  package net.sf.xframe.ex;
22  
23  import java.io.PrintStream;
24  import java.io.PrintWriter;
25  
26  /***
27   * Class from which all xframe exceptions should inherit.
28   * Allows recording of nested exceptions.
29   *
30   * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
31   */
32  public class CascadingException extends Exception {
33  
34      /*** The Throwable that caused this exception to be thrown. */
35      private final Throwable cause;
36  
37  
38      ////////////////////////////////////////////////
39      //    construction
40      ////////////////////////////////////////////////
41  
42      /***
43       * Construct a new <code>CascadingException</code> instance.
44       *
45       * @param message The detail message for this exception.
46       */
47      public CascadingException(final String message) {
48          this(message, null);
49      }
50  
51      /***
52       * Construct a new <code>CascadingException</code> instance.
53       *
54       * @param message The detail message for this exception.
55       * @param throwable the root cause of the exception
56       */
57      public CascadingException(final String message, final Throwable throwable) {
58          super(message);
59          cause = throwable;
60      }
61  
62      /***
63       * Construct a new <code>CascadingException</code> instance.
64       *
65       * @param throwable the root cause of the exception
66       */
67      public CascadingException(final Throwable throwable) {
68          super(throwable.getMessage());
69          cause = throwable;
70      }
71  
72  
73      ////////////////////////////////////////////////
74      //    interface CascadingThrowable
75      ////////////////////////////////////////////////
76  
77      /***
78       * Retrieve root cause of the exception.
79       *
80       * @return the root cause
81       */
82      public final Throwable getCause() {
83          return cause;
84      }
85  
86  
87      ////////////////////////////////////////////////
88      //    public methods
89      ////////////////////////////////////////////////
90  
91      /***
92       * Prints this <code>Throwable</code> and its backtrace to the
93       * standard error stream.
94       *
95       * @see java.lang.Throwable#printStackTrace()
96       */
97      public final void printStackTrace() {
98          super.printStackTrace();
99      }
100 
101     /***
102      * Prints this <code>Throwable</code> and its backtrace to the
103      * specified print stream.
104      *
105      * @param s <code>PrintStream</code> to use for output
106      *
107      * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
108      */
109     public final void printStackTrace(final PrintStream s) {
110         super.printStackTrace(s);
111     }
112 
113     /***
114      * Prints this <code>Throwable</code> and its backtrace to the specified
115      * print writer.
116      *
117      * @param w <code>PrintWriter</code> to use for output
118      *
119      * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
120      */
121     public final void printStackTrace(final PrintWriter w) {
122         super.printStackTrace(w);
123     }
124 }