001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.base;
019:
020: /**
021: * The main exception class for the whole contelligent application.
022: */
023: public class ContelligentException extends Exception {
024: private Throwable t = null;
025:
026: /**
027: * Creates a new <code>ContelligentException</code> instance with the
028: * given String as additional message and with a nested
029: * <code>Throwable</code> object.
030: *
031: * @param message
032: * a non-null <code>String</code> value
033: * @param t
034: * a <code>Throwable</code> value
035: */
036: public ContelligentException(String message, Throwable t) {
037: super (message);
038: this .t = t;
039: }
040:
041: /**
042: * Creates a new <code>ContelligentException</code> instance with no
043: * additional message.
044: */
045: public ContelligentException() {
046: super ();
047: }
048:
049: /**
050: * Creates a new <code>ContelligentException</code> instance with no
051: * additional message but with a nested <code>Throwable</code> object.
052: */
053: public ContelligentException(Throwable t) {
054: super ();
055: this .t = t;
056: }
057:
058: /**
059: * Creates a new <code>ContelligentException</code> instance with the
060: * given String as additional message.
061: *
062: * @param message
063: * a non-null <code>String</code> value
064: */
065: public ContelligentException(String message) {
066: this (message, null);
067: }
068:
069: public Throwable getNested() {
070: return t;
071: }
072:
073: /**
074: * Sets the nested <code>Throwable</code>of this exception and returns
075: * the old nested or null if none was set before.
076: *
077: * @param t
078: * a <code>Throwable</code> value
079: * @return a <code>Throwable</code> value
080: */
081: public Throwable setNested(Throwable t) {
082: Throwable old = this .t;
083: this .t = t;
084: return old;
085: }
086:
087: public String toString() {
088: StringBuffer out = new StringBuffer(getClass().getName());
089: String message = getLocalizedMessage();
090: if (message != null)
091: out.append(": " + message); // append message
092:
093: if (t != null) {
094: out.append("\n->embedded exception:" + t);
095: }
096: return out.toString();
097: }
098:
099: public void printStackTrace(java.io.PrintWriter s) {
100: if (t == null) {
101: super.printStackTrace(s);
102: } else {
103: s.println(toString());
104: t.printStackTrace(s);
105: }
106: }
107:
108: }
|