KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > exception > WrappedRuntimeException


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.exception;
5
6 import java.io.PrintStream JavaDoc;
7 import java.io.PrintWriter JavaDoc;
8
9 /**
10  * Wrappes the original throwable in a RuntimeException.
11  *
12  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
13  */

14 public class WrappedRuntimeException extends RuntimeException JavaDoc {
15   /**
16    * The original throwable instance.
17    */

18   private final Throwable JavaDoc m_throwable;
19
20   /**
21    * The exception user provided message when the exception is wrapped
22    */

23   private final String JavaDoc m_message;
24
25   /**
26    * Creates a new WrappedRuntimeException.
27    *
28    * @param throwable the non-RuntimeException to be wrapped.
29    */

30   public WrappedRuntimeException(final Throwable JavaDoc throwable) {
31     m_throwable = throwable;
32     m_message = throwable.getMessage();
33   }
34
35   /**
36    * Creates a new WrappedRuntimeException.
37    *
38    * @param message
39    * @param throwable the non-RuntimeException to be wrapped.
40    */

41   public WrappedRuntimeException(final String JavaDoc message, final Throwable JavaDoc throwable) {
42     m_throwable = throwable;
43     m_message = message;
44   }
45
46   /**
47    * Returns the error message string of the wrapped exception.
48    *
49    * @return the error message string of the wrapped exception
50    */

51   public String JavaDoc getMessage() {
52     return m_message;
53   }
54
55   /**
56    * Returns the localized description of the wrapped exception in order to produce a locale-specific message.
57    *
58    * @return the localized description of the wrapped exception.
59    */

60   public String JavaDoc getLocalizedMessage() {
61     return m_throwable.getLocalizedMessage();
62   }
63
64   /**
65    * Returns the original exception.
66    *
67    * @return the cause
68    */

69   public Throwable JavaDoc getCause() {
70     return m_throwable;
71   }
72
73   /**
74    * Returns a short description of the wrapped exception.
75    *
76    * @return a string representation of the wrapped exception.
77    */

78   public String JavaDoc toString() {
79     return (m_message==null ? "" : m_message) + "; " + m_throwable.toString();
80   }
81
82   ///CLOVER:OFF
83

84   /**
85    * Prints the wrapped exception A its backtrace to the standard error stream.
86    */

87   public void printStackTrace() {
88     m_throwable.printStackTrace();
89   }
90
91   /**
92    * Prints the wrapped excpetion A its backtrace to the specified print stream.
93    *
94    * @param s the print stream
95    */

96   public void printStackTrace(final PrintStream JavaDoc s) {
97     m_throwable.printStackTrace(s);
98   }
99
100   /**
101    * Prints the wrapped exception A its backtrace to the specified print writer.
102    *
103    * @param s the print writer
104    */

105   public void printStackTrace(final PrintWriter JavaDoc s) {
106     m_throwable.printStackTrace(s);
107   }
108
109   ///CLOVER:ON
110
}
Popular Tags