001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller;
020:
021: import java.io.PrintStream;
022: import java.io.PrintWriter;
023:
024: /**
025: * Base Roller exception class.
026: */
027: public class RollerException extends Exception {
028:
029: private Throwable mRootCause = null;
030:
031: /**
032: * Construct emtpy exception object.
033: */
034: public RollerException() {
035: super ();
036: }
037:
038: /**
039: * Construct RollerException with message string.
040: * @param s Error message string.
041: */
042: public RollerException(String s) {
043: super (s);
044: }
045:
046: /**
047: * Construct RollerException, wrapping existing throwable.
048: * @param s Error message
049: * @param t Existing connection to wrap.
050: */
051: public RollerException(String s, Throwable t) {
052: super (s);
053: mRootCause = t;
054: }
055:
056: /**
057: * Construct RollerException, wrapping existing throwable.
058: * @param t Existing exception to be wrapped.
059: */
060: public RollerException(Throwable t) {
061: mRootCause = t;
062: }
063:
064: /**
065: * Get root cause object, or null if none.
066: * @return Root cause or null if none.
067: */
068: public Throwable getRootCause() {
069: return mRootCause;
070: }
071:
072: /**
073: * Get root cause message.
074: * @return Root cause message.
075: */
076: public String getRootCauseMessage() {
077: String rcmessage = null;
078: if (getRootCause() != null) {
079: if (getRootCause().getCause() != null) {
080: rcmessage = getRootCause().getCause().getMessage();
081: }
082: rcmessage = (rcmessage == null) ? getRootCause()
083: .getMessage() : rcmessage;
084: rcmessage = (rcmessage == null) ? super .getMessage()
085: : rcmessage;
086: rcmessage = (rcmessage == null) ? "NONE" : rcmessage;
087: }
088: return rcmessage;
089: }
090:
091: /**
092: * Print stack trace for exception and for root cause exception if htere is one.
093: * @see java.lang.Throwable#printStackTrace()
094: */
095: public void printStackTrace() {
096: super .printStackTrace();
097: if (mRootCause != null) {
098: System.out.println("--- ROOT CAUSE ---");
099: mRootCause.printStackTrace();
100: }
101: }
102:
103: /**
104: * Print stack trace for exception and for root cause exception if htere is one.
105: * @param s Stream to print to.
106: */
107: public void printStackTrace(PrintStream s) {
108: super .printStackTrace(s);
109: if (mRootCause != null) {
110: s.println("--- ROOT CAUSE ---");
111: mRootCause.printStackTrace(s);
112: }
113: }
114:
115: /**
116: * Print stack trace for exception and for root cause exception if htere is one.
117: * @param s Writer to write to.
118: */
119: public void printStackTrace(PrintWriter s) {
120: super .printStackTrace(s);
121: if (null != mRootCause) {
122: s.println("--- ROOT CAUSE ---");
123: mRootCause.printStackTrace(s);
124: }
125: }
126:
127: }
|