001: /*
002: * $Id: GeneralRuntimeException.java,v 1.1 2003/08/15 20:23:20 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 Runtime Exception, provides nested exceptions, etc
031: *
032: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
033: * @version $Revision: 1.1 $
034: * @since 1.0
035: */
036: public class GeneralRuntimeException extends RuntimeException {
037:
038: Throwable nested = null;
039:
040: /**
041: * Creates new <code>GeneralException</code> without detail message.
042: */
043: public GeneralRuntimeException() {
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 GeneralRuntimeException(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 GeneralRuntimeException(String msg, Throwable nested) {
060: super (msg);
061: this .nested = nested;
062: }
063:
064: /** Returns the detail message, including the message from the nested exception if there is one. */
065: public String getMessage() {
066: if (nested != null)
067: return super .getMessage() + " (" + nested.getMessage()
068: + ")";
069: else
070: return super .getMessage();
071: }
072:
073: /** Returns the detail message, NOT including the message from the nested exception. */
074: public String getNonNestedMessage() {
075: return super .getMessage();
076: }
077:
078: /** Returns the nested exception if there is one, null if there is not. */
079: public Throwable getNested() {
080: return nested;
081: }
082:
083: /** Prints the composite message to System.err. */
084: public void printStackTrace() {
085: super .printStackTrace();
086: if (nested != null)
087: nested.printStackTrace();
088: }
089:
090: /** Prints the composite message and the embedded stack trace to the specified stream ps. */
091: public void printStackTrace(PrintStream ps) {
092: super .printStackTrace(ps);
093: if (nested != null)
094: nested.printStackTrace(ps);
095: }
096:
097: /** Prints the composite message and the embedded stack trace to the specified print writer pw. */
098: public void printStackTrace(PrintWriter pw) {
099: super.printStackTrace(pw);
100: if (nested != null)
101: nested.printStackTrace(pw);
102: }
103: }
|