KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > RollerException


1
2 package org.roller;
3
4 import java.io.PrintStream JavaDoc;
5 import java.io.PrintWriter JavaDoc;
6
7 /**
8  * Roller services interfaces throw this exception.
9  */

10 public class RollerException extends Exception JavaDoc
11 {
12     private Throwable JavaDoc mRootCause = null;
13     
14     /**
15      * Construct RollerException, wrapping existing throwable.
16      * @param s Error message
17      * @param t Existing connection to wrap.
18      */

19     public RollerException(String JavaDoc s,Throwable JavaDoc t)
20     {
21         super(s);
22         mRootCause = t;
23     }
24     /**
25      * Construct RollerException, wrapping existing throwable.
26      * @param t Existing exception to be wrapped.
27      */

28     public RollerException(Throwable JavaDoc t)
29     {
30         mRootCause = t;
31     }
32     /**
33      * Construct RollerException with message string.
34      * @param s Error message string.
35      */

36     public RollerException(String JavaDoc s)
37     {
38         super(s);
39     }
40     /**
41      * Construct emtpy exception object.
42      */

43     public RollerException()
44     {
45         super();
46     }
47     /**
48      * Get root cause object, or null if none.
49      * @return Root cause or null if none.
50      */

51     public Throwable JavaDoc getRootCause()
52     {
53         return mRootCause;
54     }
55    
56     /**
57      * Print stack trace for exception and for root cause exception if htere is one.
58      * @see java.lang.Throwable#printStackTrace()
59      */

60     public void printStackTrace()
61     {
62         super.printStackTrace();
63         if (mRootCause != null)
64         {
65             System.out.println("--- ROOT CAUSE ---");
66             mRootCause.printStackTrace();
67         }
68     }
69
70     /**
71      * Print stack trace for exception and for root cause exception if htere is one.
72      * @param s Stream to print to.
73      */

74     public void printStackTrace(PrintStream JavaDoc s)
75     {
76         super.printStackTrace(s);
77         if (mRootCause != null)
78         {
79             s.println("--- ROOT CAUSE ---");
80             mRootCause.printStackTrace(s);
81         }
82     }
83
84     /**
85      * Print stack trace for exception and for root cause exception if htere is one.
86      * @param s Writer to write to.
87      */

88     public void printStackTrace(PrintWriter JavaDoc s)
89     {
90        super.printStackTrace(s);
91        if (null != mRootCause)
92        {
93            s.println("--- ROOT CAUSE ---");
94            mRootCause.printStackTrace(s);
95        }
96     }
97
98     /**
99      * Get root cause message.
100      * @return Root cause message.
101      */

102     public String JavaDoc getRootCauseMessage()
103     {
104         String JavaDoc rcmessage = null;
105         if (getRootCause()!=null)
106         {
107             if (getRootCause().getCause()!=null)
108             {
109                 rcmessage = getRootCause().getCause().getMessage();
110             }
111             rcmessage = (rcmessage == null) ? getRootCause().getMessage() : rcmessage;
112             rcmessage = (rcmessage == null) ? super.getMessage() : rcmessage;
113             rcmessage = (rcmessage == null) ? "NONE" : rcmessage;
114         }
115         return rcmessage;
116     }
117 }
118
119
Popular Tags