001: /*
002: * $Id: GeneralException.java,v 1.2 2004/02/19 18:44:37 ajzeneski Exp $
003: *
004: * Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024: package org.ofbiz.base.util;
025:
026: import java.io.PrintStream;
027: import java.io.PrintWriter;
028:
029: /**
030: * Base OFBiz Exception, provides nested exceptions, etc
031: *
032: *@author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
033: *@version $Revision: 1.2 $
034: *@since 1.0
035: */
036: public class GeneralException extends Exception {
037:
038: Throwable nested = null;
039:
040: /**
041: * Creates new <code>GeneralException</code> without detail message.
042: */
043: public GeneralException() {
044: super ();
045: }
046:
047: /**
048: * Constructs an <code>GeneralException</code> with the specified detail message.
049: * @param msg the detail message.
050: */
051: public GeneralException(String msg) {
052: super (msg);
053: }
054:
055: /**
056: * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception.
057: * @param msg the detail message.
058: */
059: public GeneralException(String msg, Throwable nested) {
060: super (msg);
061: this .nested = nested;
062: }
063:
064: /**
065: * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception.
066: * @param nested the detail message.
067: */
068: public GeneralException(Throwable nested) {
069: super ();
070: this .nested = nested;
071: }
072:
073: /** Returns the detail message, including the message from the nested exception if there is one. */
074: public String getMessage() {
075: if (nested != null)
076: return super .getMessage() + " (" + nested.getMessage()
077: + ")";
078: else
079: return super .getMessage();
080: }
081:
082: /** Returns the detail message, NOT including the message from the nested exception. */
083: public String getNonNestedMessage() {
084: return super .getMessage();
085: }
086:
087: /** Returns the nested exception if there is one, null if there is not. */
088: public Throwable getNested() {
089: if (nested == null)
090: return this ;
091: return nested;
092: }
093:
094: /** Prints the composite message to System.err. */
095: public void printStackTrace() {
096: super .printStackTrace();
097: if (nested != null)
098: nested.printStackTrace();
099: }
100:
101: /** Prints the composite message and the embedded stack trace to the specified stream ps. */
102: public void printStackTrace(PrintStream ps) {
103: super .printStackTrace(ps);
104: if (nested != null)
105: nested.printStackTrace(ps);
106: }
107:
108: /** Prints the composite message and the embedded stack trace to the specified print writer pw. */
109: public void printStackTrace(PrintWriter pw) {
110: super.printStackTrace(pw);
111: if (nested != null)
112: nested.printStackTrace(pw);
113: }
114: }
|