KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > RollerException


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller;
20
21 import java.io.PrintStream JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23
24
25 /**
26  * Base Roller exception class.
27  */

28 public class RollerException extends Exception JavaDoc {
29     
30     private Throwable JavaDoc mRootCause = null;
31     
32     
33     /**
34      * Construct emtpy exception object.
35      */

36     public RollerException() {
37         super();
38     }
39     
40     
41     /**
42      * Construct RollerException with message string.
43      * @param s Error message string.
44      */

45     public RollerException(String JavaDoc s) {
46         super(s);
47     }
48     
49     
50     /**
51      * Construct RollerException, wrapping existing throwable.
52      * @param s Error message
53      * @param t Existing connection to wrap.
54      */

55     public RollerException(String JavaDoc s, Throwable JavaDoc t) {
56         super(s);
57         mRootCause = t;
58     }
59     
60     
61     /**
62      * Construct RollerException, wrapping existing throwable.
63      * @param t Existing exception to be wrapped.
64      */

65     public RollerException(Throwable JavaDoc t) {
66         mRootCause = t;
67     }
68     
69     
70     /**
71      * Get root cause object, or null if none.
72      * @return Root cause or null if none.
73      */

74     public Throwable JavaDoc getRootCause() {
75         return mRootCause;
76     }
77     
78     
79     /**
80      * Get root cause message.
81      * @return Root cause message.
82      */

83     public String JavaDoc getRootCauseMessage() {
84         String JavaDoc rcmessage = null;
85         if (getRootCause()!=null) {
86             if (getRootCause().getCause()!=null) {
87                 rcmessage = getRootCause().getCause().getMessage();
88             }
89             rcmessage = (rcmessage == null) ? getRootCause().getMessage() : rcmessage;
90             rcmessage = (rcmessage == null) ? super.getMessage() : rcmessage;
91             rcmessage = (rcmessage == null) ? "NONE" : rcmessage;
92         }
93         return rcmessage;
94     }
95     
96     
97     /**
98      * Print stack trace for exception and for root cause exception if htere is one.
99      * @see java.lang.Throwable#printStackTrace()
100      */

101     public void printStackTrace() {
102         super.printStackTrace();
103         if (mRootCause != null) {
104             System.out.println("--- ROOT CAUSE ---");
105             mRootCause.printStackTrace();
106         }
107     }
108     
109     
110     /**
111      * Print stack trace for exception and for root cause exception if htere is one.
112      * @param s Stream to print to.
113      */

114     public void printStackTrace(PrintStream JavaDoc s) {
115         super.printStackTrace(s);
116         if (mRootCause != null) {
117             s.println("--- ROOT CAUSE ---");
118             mRootCause.printStackTrace(s);
119         }
120     }
121     
122     
123     /**
124      * Print stack trace for exception and for root cause exception if htere is one.
125      * @param s Writer to write to.
126      */

127     public void printStackTrace(PrintWriter JavaDoc s) {
128         super.printStackTrace(s);
129         if (null != mRootCause) {
130             s.println("--- ROOT CAUSE ---");
131             mRootCause.printStackTrace(s);
132         }
133     }
134     
135 }
136
Popular Tags