001: package net.sourceforge.squirrel_sql.fw.util;
002:
003: /*
004: * Copyright (C) 2001-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.io.PrintStream;
022: import java.io.PrintWriter;
023:
024: /**
025: * Base runtime exception.
026: *
027: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
028: */
029: public class BaseRuntimeException extends RuntimeException {
030: /** If this exception is wrapped around another it is stored here. */
031: private Throwable _wrapee;
032:
033: /**
034: * Default ctor. Creates an exception with an empty string ("")
035: * as its message.
036: */
037: public BaseRuntimeException() {
038: this ("");
039: }
040:
041: /**
042: * Ctor specifying the message.
043: *
044: * @param msg The message.
045: */
046: public BaseRuntimeException(String msg) {
047: super (msg != null ? msg : "");
048: }
049:
050: /**
051: * Ctor specifying an exception that this one should
052: * be wrapped around.
053: *
054: * @param wrapee The wrapped exception.
055: */
056: public BaseRuntimeException(Throwable wrapee) {
057: super (getMessageFromException(wrapee));
058: _wrapee = wrapee;
059: }
060:
061: public String toString() {
062: if (_wrapee != null) {
063: return _wrapee.toString();
064: }
065: return super .toString();
066: }
067:
068: public void printStackTrace() {
069: if (_wrapee != null) {
070: _wrapee.printStackTrace();
071: } else {
072: super .printStackTrace();
073: }
074: }
075:
076: public void printStackTrace(PrintStream s) {
077: if (_wrapee != null) {
078: _wrapee.printStackTrace(s);
079: } else {
080: super .printStackTrace(s);
081: }
082: }
083:
084: public void printStackTrace(PrintWriter wtr) {
085: if (_wrapee != null) {
086: _wrapee.printStackTrace(wtr);
087: } else {
088: super .printStackTrace(wtr);
089: }
090: }
091:
092: /**
093: * Retrieve the exception that this one is wrapped around. This can be
094: * <TT>null</TT>.
095: *
096: * @return The wrapped exception or <TT>null</TT>.
097: */
098: public Throwable getWrappedThrowable() {
099: return _wrapee;
100: }
101:
102: private static String getMessageFromException(Throwable th) {
103: String rtn = "";
104: if (th != null) {
105: String msg = th.getMessage();
106: if (msg != null) {
107: rtn = msg;
108: }
109: }
110: return rtn;
111: }
112: }
|