KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > CompositeRuntimeException


1 package org.sapia.util;
2
3
4 // Import of Sun's JDK classes
5
// ---------------------------
6
import java.io.PrintStream JavaDoc;
7 import java.io.PrintWriter JavaDoc;
8
9
10 /**
11  * This class can be extended by other runtime exception classes that require
12  * encapsulating another exception, and provide the latter's stack trace and
13  * message instead of its own.
14  *
15  * @author Jean-Cedric Desrochers
16  * <dl>
17  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
18  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
19  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
20  * </dl>
21  */

22 public class CompositeRuntimeException extends RuntimeException JavaDoc {
23   /////////////////////////////////////////////////////////////////////////////////////////
24
///////////////////////////////// INSTANCE ATTRIBUTES /////////////////////////////////
25
/////////////////////////////////////////////////////////////////////////////////////////
26

27   /** The source error that is encapsulated in this composite exception. */
28   private Throwable JavaDoc _theSourceError;
29
30   /////////////////////////////////////////////////////////////////////////////////////////
31
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
32
/////////////////////////////////////////////////////////////////////////////////////////
33

34   /**
35    * Creates a new CompositeRuntimeException instance with the arguments passed in.
36    *
37    * @param aMessage The message describing the error.
38    * @param aSourceError The source error to encapsulate.
39    */

40   public CompositeRuntimeException(String JavaDoc aMessage, Throwable JavaDoc aSourceError) {
41     super(aMessage);
42     _theSourceError = aSourceError;
43   }
44
45   /**
46    * Creates a new CompositeRuntimeException instance with the argument passed in.
47    *
48    * @param aMessage The message describing the error.
49    */

50   public CompositeRuntimeException(String JavaDoc aMessage) {
51     super(aMessage);
52   }
53
54   /////////////////////////////////////////////////////////////////////////////////////////
55
////////////////////////////////// ACCESSOR METHODS ///////////////////////////////////
56
/////////////////////////////////////////////////////////////////////////////////////////
57

58   /**
59    * Returns the source error encapsulated in this composite exception.
60    *
61    * @return The source error encapsulated in this composite exception.
62    */

63   public Throwable JavaDoc getSourceError() {
64     return _theSourceError;
65   }
66
67   /////////////////////////////////////////////////////////////////////////////////////////
68
////////////////////////////////// OVERRIDEN METHODS //////////////////////////////////
69
/////////////////////////////////////////////////////////////////////////////////////////
70

71   /**
72    * Prints the stack trace of this composite exception to the standard error stream.
73    */

74   public void printStackTrace() {
75     printStackTrace(System.err);
76   }
77
78   /**
79    * Prints the stack trace of this composite exception to the print writer passed in.
80    */

81   public void printStackTrace(PrintWriter JavaDoc anOutput) {
82     super.printStackTrace(anOutput);
83
84     if (_theSourceError != null) {
85       anOutput.print("\n---> NESTED EXCEPTION IS: ");
86       _theSourceError.printStackTrace(anOutput);
87     }
88   }
89
90   /**
91    * Prints the stack trace of this composite exception to the print stream passed in.
92    */

93   public void printStackTrace(PrintStream JavaDoc anOutput) {
94     super.printStackTrace(anOutput);
95
96     if (_theSourceError != null) {
97       anOutput.print("\n---> NESTED EXCEPTION IS: ");
98       _theSourceError.printStackTrace(anOutput);
99     }
100   }
101 }
102
Popular Tags