001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.exception;
005:
006: import java.io.PrintStream;
007: import java.io.PrintWriter;
008:
009: /**
010: * Wrappes the original throwable in a RuntimeException.
011: *
012: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
013: */
014: public class WrappedRuntimeException extends RuntimeException {
015: /**
016: * The original throwable instance.
017: */
018: private final Throwable m_throwable;
019:
020: /**
021: * The exception user provided message when the exception is wrapped
022: */
023: private final String m_message;
024:
025: /**
026: * Creates a new WrappedRuntimeException.
027: *
028: * @param throwable the non-RuntimeException to be wrapped.
029: */
030: public WrappedRuntimeException(final Throwable throwable) {
031: m_throwable = throwable;
032: m_message = throwable.getMessage();
033: }
034:
035: /**
036: * Creates a new WrappedRuntimeException.
037: *
038: * @param message
039: * @param throwable the non-RuntimeException to be wrapped.
040: */
041: public WrappedRuntimeException(final String message,
042: final Throwable throwable) {
043: m_throwable = throwable;
044: m_message = message;
045: }
046:
047: /**
048: * Returns the error message string of the wrapped exception.
049: *
050: * @return the error message string of the wrapped exception
051: */
052: public String getMessage() {
053: return m_message;
054: }
055:
056: /**
057: * Returns the localized description of the wrapped exception in order to produce a locale-specific message.
058: *
059: * @return the localized description of the wrapped exception.
060: */
061: public String getLocalizedMessage() {
062: return m_throwable.getLocalizedMessage();
063: }
064:
065: /**
066: * Returns the original exception.
067: *
068: * @return the cause
069: */
070: public Throwable getCause() {
071: return m_throwable;
072: }
073:
074: /**
075: * Returns a short description of the wrapped exception.
076: *
077: * @return a string representation of the wrapped exception.
078: */
079: public String toString() {
080: return (m_message == null ? "" : m_message) + "; "
081: + m_throwable.toString();
082: }
083:
084: ///CLOVER:OFF
085:
086: /**
087: * Prints the wrapped exception A its backtrace to the standard error stream.
088: */
089: public void printStackTrace() {
090: m_throwable.printStackTrace();
091: }
092:
093: /**
094: * Prints the wrapped excpetion A its backtrace to the specified print stream.
095: *
096: * @param s the print stream
097: */
098: public void printStackTrace(final PrintStream s) {
099: m_throwable.printStackTrace(s);
100: }
101:
102: /**
103: * Prints the wrapped exception A its backtrace to the specified print writer.
104: *
105: * @param s the print writer
106: */
107: public void printStackTrace(final PrintWriter s) {
108: m_throwable.printStackTrace(s);
109: }
110:
111: ///CLOVER:ON
112: }
|