KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > ToolException


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.common;
25 //
26
import java.io.*;
27 import java.util.ResourceBundle JavaDoc;
28 //
29
public class ToolException extends Exception JavaDoc {
30
31     static ResourceBundle JavaDoc res =
32         ResourceBundle.getBundle("org.enhydra.tool.common.Res"); // nores
33

34     //
35
private Throwable JavaDoc parent = null;
36     private final boolean debug = false;
37
38     /**
39      * Create a ToolException with a specified error message.
40      *
41      * @param message
42      * Message providing information on the nature of the exception.
43      */

44     public ToolException(String JavaDoc message) {
45         super(message);
46     }
47
48     /**
49      * Create a ToolException linked to a parent exception.
50      *
51      * @param chain
52      * Parent exception to include in stack trace.
53      * @param message
54      * Message providing information on the nature of the exception.
55      */

56     public ToolException(Throwable JavaDoc chain, String JavaDoc message) {
57         super(message);
58         parent = chain;
59         if (debug) {
60           System.err.println("-----------------------");
61           parent.printStackTrace(System.err);
62           System.err.println("-----------------------");
63         }
64     }
65
66     /**
67      * Get a string containing messages from all members of
68      * exception chain.
69      *
70      * @return
71      * All messages from exceptions in the chain with line feed delimiters.
72      */

73     public String JavaDoc getMessage() {
74         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
75
76         buf.append(ResUtil.format(res.getString("Tool_Exception_n_0_"),
77                                   super.getMessage()));
78         if (parent != null) {
79             buf.append('\n');
80             buf.append(" " + parent.getMessage()); // nores
81
}
82         return buf.toString();
83     }
84
85     /**
86      * Print a recursive stack trace including all members of
87      * exception chain.
88      */

89     public void printStackTrace() {
90         super.printStackTrace();
91         if (parent != null) {
92             parent.printStackTrace();
93         }
94     }
95
96     public void printStackTrace(PrintStream stream) {
97         super.printStackTrace(stream);
98         if (parent != null) {
99             parent.printStackTrace(stream);
100         }
101     }
102
103
104 }
105
Popular Tags