KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 ProActiveRuntimeException extends RuntimeException JavaDoc {
42
43   protected Throwable JavaDoc detail;
44
45   /**
46   * Constructs a <code>ProActiveRuntimeException</code> with no specified
47   * detail message.
48   */

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

55   public ProActiveRuntimeException(String JavaDoc s) {
56     super(s);
57   }
58
59   /**
60   * Constructs a <code>ProActiveRuntimeException</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 ProActiveRuntimeException(String JavaDoc s, Throwable JavaDoc ex) {
66     super(s);
67     detail = ex;
68   }
69
70   /**
71   * Constructs a <code>ProActiveRuntimeException</code> with the specified
72   * detail message and nested exception.
73   * @param ex the nested exception
74   */

75   public ProActiveRuntimeException(Throwable JavaDoc ex) {
76     super();
77     detail = ex;
78   }
79
80   /**
81   * Returns the detail message, including the message from the nested
82   * exception if there is one.
83   */

84   public String JavaDoc getMessage() {
85     if (detail == null)
86       return super.getMessage();
87     else {
88       if (super.getMessage() == null)
89         return detail.getMessage();
90       else return super.getMessage() + "; nested exception is: \n" + detail.toString();
91     }
92   }
93
94
95   public Throwable JavaDoc getTargetException() {
96     return detail;
97   }
98
99
100   /**
101   * Prints the composite message and the embedded stack trace to
102   * the specified stream <code>ps</code>.
103   * @param ps the print stream
104   */

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

119   public void printStackTrace() {
120     printStackTrace(System.err);
121   }
122
123   /**
124   * Prints the composite message and the embedded stack trace to
125   * the specified print writer <code>pw</code>.
126   * @param pw the print writer
127   */

128   public void printStackTrace(java.io.PrintWriter JavaDoc pw) {
129     if (detail == null) {
130       super.printStackTrace(pw);
131     } else {
132       synchronized(pw) {
133         pw.println(getMessage());
134         detail.printStackTrace(pw);
135       }
136     }
137   }
138   
139 }
140
Popular Tags