KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: GeneralRuntimeException.java 5462 2005-08-05 18:35:48Z jonesde $
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
29 /**
30  * Base OFBiz Runtime Exception, provides nested exceptions, etc
31  *
32  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
33  * @version $Rev: 5462 $
34  * @since 1.0
35  */

36 public class GeneralRuntimeException extends RuntimeException JavaDoc {
37
38     Throwable JavaDoc nested = null;
39
40     /**
41      * Creates new <code>GeneralException</code> without detail message.
42      */

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

51     public GeneralRuntimeException(String JavaDoc msg) {
52         super(msg);
53     }
54
55     /**
56      * Constructs an <code>GeneralException</code> with a nested Exception.
57      * @param nested the nested exception.
58      */

59     public GeneralRuntimeException(Throwable JavaDoc nested) {
60         super();
61         this.nested = nested;
62     }
63
64     /**
65      * Constructs an <code>GeneralException</code> with the specified detail message and nested Exception.
66      * @param msg the detail message.
67      */

68     public GeneralRuntimeException(String JavaDoc msg, Throwable JavaDoc nested) {
69         super(msg);
70         this.nested = nested;
71     }
72
73     /** Returns the detail message, including the message from the nested exception if there is one. */
74     public String JavaDoc getMessage() {
75         if (nested != null)
76             return super.getMessage() + " (" + nested.getMessage() + ")";
77         else
78             return super.getMessage();
79     }
80
81     /** Returns the detail message, NOT including the message from the nested exception. */
82     public String JavaDoc getNonNestedMessage() {
83         return super.getMessage();
84     }
85
86     /** Returns the nested exception if there is one, null if there is not. */
87     public Throwable JavaDoc getNested() {
88         return nested;
89     }
90
91     /** Prints the composite message to System.err. */
92     public void printStackTrace() {
93         super.printStackTrace();
94         if (nested != null) nested.printStackTrace();
95     }
96
97     /** Prints the composite message and the embedded stack trace to the specified stream ps. */
98     public void printStackTrace(PrintStream JavaDoc ps) {
99         super.printStackTrace(ps);
100         if (nested != null) nested.printStackTrace(ps);
101     }
102
103     /** Prints the composite message and the embedded stack trace to the specified print writer pw. */
104     public void printStackTrace(PrintWriter JavaDoc pw) {
105         super.printStackTrace(pw);
106         if (nested != null) nested.printStackTrace(pw);
107     }
108 }
109
Popular Tags