KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > exception > WrappedRuntimeException


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

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

18 public class WrappedRuntimeException extends RuntimeException JavaDoc {
19     /**
20      * The original throwable instance.
21      */

22     private final Throwable JavaDoc m_throwable;
23
24     /**
25      * The exception user provided message when the exception is wrapped
26      */

27     private final String JavaDoc m_message;
28
29     /**
30      * Creates a new WrappedRuntimeException.
31      *
32      * @param throwable the non-RuntimeException to be wrapped.
33      */

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

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

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

64     public String JavaDoc getLocalizedMessage() {
65         return m_throwable.getLocalizedMessage();
66     }
67
68     /**
69      * Returns the original exception.
70      *
71      * @return the cause
72      */

73     public Throwable JavaDoc getCause() {
74         return m_throwable;
75     }
76
77     /**
78      * Returns a short description of the wrapped exception.
79      *
80      * @return a string representation of the wrapped exception.
81      */

82     public String JavaDoc toString() {
83         return m_throwable.toString();
84     }
85
86     ///CLOVER:OFF
87

88     /**
89      * Prints the wrapped exception A its backtrace to the standard error stream.
90      */

91     public void printStackTrace() {
92         m_throwable.printStackTrace();
93     }
94
95     /**
96      * Prints the wrapped excpetion A its backtrace to the specified print stream.
97      *
98      * @param s the print stream
99      */

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

109     public void printStackTrace(final PrintWriter JavaDoc s) {
110         m_throwable.printStackTrace(s);
111     }
112
113     ///CLOVER:ON
114
}
Popular Tags