001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.base.util;
019:
020: import java.io.PrintStream;
021: import java.io.PrintWriter;
022:
023: /**
024: * Base OFBiz Runtime Exception, provides nested exceptions, etc
025: *
026: */
027: public class GeneralRuntimeException extends RuntimeException {
028:
029: Throwable nested = null;
030:
031: /**
032: * Creates new <code>GeneralException</code> without detail message.
033: */
034: public GeneralRuntimeException() {
035: super ();
036: }
037:
038: /**
039: * Constructs an <code>GeneralException</code> with the specified detail message.
040: * @param msg the detail message.
041: */
042: public GeneralRuntimeException(String msg) {
043: super (msg);
044: }
045:
046: /**
047: * Constructs an <code>GeneralException</code> with a nested Exception.
048: * @param nested the nested exception.
049: */
050: public GeneralRuntimeException(Throwable nested) {
051: super ();
052: this .nested = nested;
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: }
|