KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > ProActiveException


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core;
32
33 /**
34  * Generic exception root of all non runtime custom exceptions in ProActive
35  *
36  * @author ProActive Team
37  * @version 1.0, 2001/10/23
38  * @since ProActive 0.9
39  *
40  */

41 public class ProActiveException extends Exception JavaDoc {
42
43   public Throwable JavaDoc detail;
44  
45   /**
46   * Constructs a <code>ProActiveException</code> with no specified
47   * detail message.
48   */

49   public ProActiveException() {}
50
51   /**
52   * Constructs a <code>ProActiveException</code> with the specified detail message.
53   * @param s the detail message
54   */

55   public ProActiveException(String JavaDoc s) {
56     super(s);
57   }
58
59   /**
60   * Constructs a <code>ProActiveException</code> with the specified
61   * detail message and nested exception.
62   * @param s the detail message
63   * @param ex the nested exception
64   */

65   public ProActiveException(String JavaDoc s, Throwable JavaDoc ex) {
66     super(s);
67     detail = ex;
68   }
69
70
71   /**
72   * Constructs a <code>ProActiveException</code> with the specified
73   * detail message and nested exception.
74   * @param ex the nested exception
75   */

76   public ProActiveException(Throwable JavaDoc ex) {
77     super();
78     detail = ex;
79   }
80
81
82   /**
83   * Returns the embedded target exception or null.
84   * @return the embedded target exception or null.
85   */

86   public Throwable JavaDoc getTargetException() {
87     return detail;
88   }
89
90   
91   /**
92   * Returns the detail message, including the message from the nested
93   * exception if there is one.
94   */

95   public String JavaDoc getMessage() {
96     if (detail == null)
97       return super.getMessage();
98     else {
99       if (super.getMessage() == null)
100         return detail.getMessage();
101       else return super.getMessage() + "; nested exception is: \n" + detail.toString();
102     }
103   }
104
105   /**
106   * Prints the composite message and the embedded stack trace to
107   * the specified stream <code>ps</code>.
108   * @param ps the print stream
109   */

110   public void printStackTrace(java.io.PrintStream JavaDoc ps) {
111     if (detail == null) {
112       super.printStackTrace(ps);
113     } else {
114       synchronized(ps) {
115         ps.println(getMessage());
116         detail.printStackTrace(ps);
117       }
118     }
119   }
120
121   /**
122   * Prints the composite message to <code>System.err</code>.
123   */

124   public void printStackTrace() {
125     printStackTrace(System.err);
126   }
127
128   /**
129   * Prints the composite message and the embedded stack trace to
130   * the specified print writer <code>pw</code>.
131   * @param pw the print writer
132   */

133   public void printStackTrace(java.io.PrintWriter JavaDoc pw) {
134     if (detail == null) {
135       super.printStackTrace(pw);
136     } else {
137       synchronized(pw) {
138         pw.println(getMessage());
139         detail.printStackTrace(pw);
140       }
141     }
142   }
143   
144 }
145
Popular Tags