001: package net.sourceforge.squirrel_sql.fw.util;
002:
003: /*
004: * Copyright (C) 2001-2004 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 exception class.
026: *
027: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
028: */
029: public class BaseException extends Exception {
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 BaseException() {
038: this ("");
039: }
040:
041: /**
042: * Ctor specifying the message.
043: *
044: * @param msg The message.
045: */
046: public BaseException(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 BaseException(Throwable wrapee) {
057: super (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: private static String getMessageFromException(Throwable th) {
093: String rtn = "";
094: if (th != null) {
095: String msg = th.getMessage();
096: if (msg != null) {
097: rtn = msg;
098: }
099: }
100: return rtn;
101: }
102:
103: /**
104: * Retrieve the exception that this one is wrapped around. This can be
105: * <TT>null</TT>.
106: *
107: * @return The wrapped exception or <TT>null</TT>.
108: */
109: public Throwable getWrappedThrowable() {
110: return _wrapee;
111: }
112: }
|