001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package org.codehaus.aspectwerkz.exception;
008:
009: import java.io.PrintStream;
010: import java.io.PrintWriter;
011:
012: /**
013: * Wrappes the original throwable in a RuntimeException.
014: *
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: */
017: public class WrappedRuntimeException extends RuntimeException {
018: /**
019: * The original throwable instance.
020: */
021: private final Throwable m_throwable;
022:
023: /**
024: * The exception user provided message when the exception is wrapped
025: */
026: private final String m_message;
027:
028: /**
029: * Creates a new WrappedRuntimeException.
030: *
031: * @param throwable the non-RuntimeException to be wrapped.
032: */
033: public WrappedRuntimeException(final Throwable throwable) {
034: m_throwable = throwable;
035: m_message = throwable.getMessage();
036: }
037:
038: /**
039: * Creates a new WrappedRuntimeException.
040: *
041: * @param message
042: * @param throwable the non-RuntimeException to be wrapped.
043: */
044: public WrappedRuntimeException(final String message,
045: final Throwable throwable) {
046: m_throwable = throwable;
047: m_message = message;
048: }
049:
050: /**
051: * Returns the error message string of the wrapped exception.
052: *
053: * @return the error message string of the wrapped exception
054: */
055: public String getMessage() {
056: return m_message;
057: }
058:
059: /**
060: * Returns the localized description of the wrapped exception in order to produce a locale-specific message.
061: *
062: * @return the localized description of the wrapped exception.
063: */
064: public String getLocalizedMessage() {
065: return m_throwable.getLocalizedMessage();
066: }
067:
068: /**
069: * Returns the original exception.
070: *
071: * @return the cause
072: */
073: public Throwable getCause() {
074: return m_throwable;
075: }
076:
077: /**
078: * Returns a short description of the wrapped exception.
079: *
080: * @return a string representation of the wrapped exception.
081: */
082: public String toString() {
083: return m_throwable.toString();
084: }
085:
086: ///CLOVER:OFF
087:
088: /**
089: * Prints the wrapped exception A its backtrace to the standard error stream.
090: */
091: public void printStackTrace() {
092: m_throwable.printStackTrace();
093: }
094:
095: /**
096: * Prints the wrapped excpetion A its backtrace to the specified print stream.
097: *
098: * @param s the print stream
099: */
100: public void printStackTrace(final PrintStream 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 s) {
110: m_throwable.printStackTrace(s);
111: }
112:
113: ///CLOVER:ON
114: }
|