KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > utils > ChainedException


1 /* ****************************************************************************
2  * ChainedException.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.utils;
11
12 import java.io.PrintStream JavaDoc;
13
14 /** A checked chained exception. */
15 public class ChainedException extends RuntimeException JavaDoc
16 {
17     Throwable JavaDoc cause = null;
18     
19     /** Constructs an instance.
20      *
21      * @param message a string
22      */

23     public ChainedException(String JavaDoc message) {
24         super(message);
25     }
26
27     /** Constructs a new runtime exception with the specified detail
28      * message and cause.
29      *
30      * @param message the detail message (which is saved for later retrieval by
31      * the Throwable.getMessage() method).
32      * @param cause the cause (which is saved for later retrieval by the
33      * Throwable.getCause() method). (A null value is permitted, and indicates
34      * that the cause is nonexistent or unknown.)
35      */

36     public ChainedException(String JavaDoc message, Throwable JavaDoc cause) {
37         super(cause.getClass().getName() + ": " + message);
38         this.cause = cause;
39     }
40
41     /** Constructs a new runtime exception with the specified cause, which
42      * typically contains the class and detail message of cause.
43      *
44      * @param cause the cause, which is saved for later retrieval by the
45      * Throwable.getCause() method. A null value is permitted, and indicates
46      * that the cause is nonexistent or unknown.
47     */

48     public ChainedException(Throwable JavaDoc cause) {
49         super(cause.getClass().getName() + ": " + cause.getMessage());
50         this.cause = cause;
51     }
52
53     /** Returns the cause of this throwable or null if the cause is nonexistent
54      * or unknown. (The cause is the throwable that caused this throwable to get
55      * thrown.)
56      *
57      * @return the cause of this throwable or null if the cause is nonexistent
58      * or unknown.
59      */

60     public Throwable JavaDoc getCause() {
61         return this.cause;
62     }
63
64     /** Prints this throwable and its backtrace to the specified print stream.
65      *
66      * @param s PrintStream to use for output.
67      */

68     public void printStackTrace(PrintStream JavaDoc s) {
69         super.printStackTrace(s);
70         if (cause != null) {
71             s.print("Caused by: ");
72             cause.printStackTrace(s);
73         }
74     }
75
76     /** Prints this throwable and its backtrace to the specified print stream.
77      *
78      * @param s PrintWriter to use for output.
79      */

80     public void printStackTrace(java.io.PrintWriter JavaDoc pw) {
81         super.printStackTrace(pw);
82         if (cause != null) {
83             pw.println("Caused by:");
84             cause.printStackTrace(pw);
85         }
86     }
87 }
88
Popular Tags