KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > base > util > GeneralException


1 /*
2  * $Id: GeneralException.java 6419 2005-12-23 17:18:49Z jaz $
3  *
4  * Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.base.util;
25
26 import java.io.PrintStream JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28 import java.util.List JavaDoc;
29
30 /**
31  * Base OFBiz Exception, provides nested exceptions, etc
32  *
33  *@author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
34  *@version $Rev: 6419 $
35  *@since 1.0
36  */

37 public class GeneralException extends Exception JavaDoc {
38
39     Throwable JavaDoc nested = null;
40     List JavaDoc messages = null;
41
42     /**
43      * Creates new <code>GeneralException</code> without detail message.
44      */

45     public GeneralException() {
46         super();
47     }
48
49     /**
50      * Constructs an <code>GeneralException</code> with the specified detail message.
51      * @param msg the detail message.
52      */

53     public GeneralException(String JavaDoc msg) {
54         super(msg);
55     }
56
57     /**
58      * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception.
59      * @param msg the detail message.
60      * @param nested the nested exception.
61      */

62     public GeneralException(String JavaDoc msg, Throwable JavaDoc nested) {
63         super(msg);
64         this.nested = nested;
65     }
66
67     /**
68      * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception.
69      * @param nested the nested exception.
70      */

71     public GeneralException(Throwable JavaDoc nested) {
72         super();
73         this.nested = nested;
74     }
75
76     /**
77      * Constructs an <code>GeneralException</code> with the specified detail message, list and nested Exception.
78      * @param msg the detail message.
79      * @param messages error message list.
80      */

81     public GeneralException(String JavaDoc msg, List JavaDoc messages) {
82         super(msg);
83         this.messages = messages;
84     }
85
86     /**
87      * Constructs an <code>GeneralException</code> with the specified detail message, list and nested Exception.
88      * @param msg the detail message.
89      * @param messages error message list.
90      * @param nested the nexted exception
91      */

92     public GeneralException(String JavaDoc msg, List JavaDoc messages, Throwable JavaDoc nested) {
93         super(msg);
94         this.nested = nested;
95         this.messages = messages;
96     }
97
98     /**
99      * Constructs an <code>GeneralException</code> with the specified detail message list and nested Exception.
100      * @param messages error message list.
101      * @param nested the nested exception.
102      */

103     public GeneralException(List JavaDoc messages, Throwable JavaDoc nested) {
104         super();
105         this.nested = nested;
106         this.messages = messages;
107     }
108
109     public GeneralException(List JavaDoc messages) {
110         super();
111         this.messages = messages;
112     }
113
114     /** Returns the detail message, including the message from the nested exception if there is one. */
115     public String JavaDoc getMessage() {
116         if (nested != null) {
117             if (super.getMessage() == null) {
118                 return nested.getMessage();
119             } else {
120                 return super.getMessage() + " (" + nested.getMessage() + ")";
121             }
122         } else {
123             return super.getMessage();
124         }
125     }
126
127     public List JavaDoc getMessageList() {
128         return this.messages;
129     }
130
131     /** Returns the detail message, NOT including the message from the nested exception. */
132     public String JavaDoc getNonNestedMessage() {
133         return super.getMessage();
134     }
135
136     /** Returns the nested exception if there is one, null if there is not. */
137     public Throwable JavaDoc getNested() {
138         if (nested == null) {
139             return this;
140         }
141         return nested;
142     }
143
144     /** Prints the composite message to System.err. */
145     public void printStackTrace() {
146         super.printStackTrace();
147         if (nested != null) nested.printStackTrace();
148     }
149
150     /** Prints the composite message and the embedded stack trace to the specified stream ps. */
151     public void printStackTrace(PrintStream JavaDoc ps) {
152         super.printStackTrace(ps);
153         if (nested != null) nested.printStackTrace(ps);
154     }
155
156     /** Prints the composite message and the embedded stack trace to the specified print writer pw. */
157     public void printStackTrace(PrintWriter JavaDoc pw) {
158         super.printStackTrace(pw);
159         if (nested != null) nested.printStackTrace(pw);
160     }
161 }
162
163
Popular Tags