KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > mop > MOPRuntimeException


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.mop;
32
33 public abstract class MOPRuntimeException extends RuntimeException JavaDoc {
34
35   protected Throwable JavaDoc detail;
36
37   /**
38   * Constructs a <code>ProActiveRuntimeException</code> with no specified
39   * detail message.
40   */

41   public MOPRuntimeException() {}
42
43   /**
44   * Constructs a <code>ProActiveRuntimeException</code> with the specified detail message.
45   * @param s the detail message
46   */

47   public MOPRuntimeException(String JavaDoc s) {
48     super(s);
49   }
50
51   /**
52   * Constructs a <code>ProActiveRuntimeException</code> with the specified
53   * detail message and nested exception.
54   *
55   * @param s the detail message
56   * @param ex the nested exception
57   */

58   public MOPRuntimeException(String JavaDoc s, Throwable JavaDoc ex) {
59     super(s);
60     detail = ex;
61   }
62
63   /**
64   * Constructs a <code>ProActiveException</code> with the specified
65   * detail message and nested exception.
66   *
67   * @param ex the nested exception
68   */

69   public MOPRuntimeException(Throwable JavaDoc ex) {
70     super();
71     detail = ex;
72   }
73
74   /**
75   * Returns the detail message, including the message from the nested
76   * exception if there is one.
77   */

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

99   public void printStackTrace(java.io.PrintStream JavaDoc ps) {
100     if (detail == null) {
101       super.printStackTrace(ps);
102     } else {
103       synchronized(ps) {
104         ps.println(getMessage());
105         detail.printStackTrace(ps);
106       }
107     }
108   }
109
110   /**
111   * Prints the composite message to <code>System.err</code>.
112   */

113   public void printStackTrace() {
114     printStackTrace(System.err);
115   }
116
117   /**
118   * Prints the composite message and the embedded stack trace to
119   * the specified print writer <code>pw</code>.
120   * @param pw the print writer
121   */

122   public void printStackTrace(java.io.PrintWriter JavaDoc pw) {
123     if (detail == null) {
124       super.printStackTrace(pw);
125     } else {
126       synchronized(pw) {
127         pw.println(getMessage());
128         detail.printStackTrace(pw);
129       }
130     }
131   }
132   
133 }
134
135
Popular Tags