KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > util > ChainedRuntimeException


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  *
22  * $Id: ChainedRuntimeException.java,v 1.1 2005/07/13 11:09:06 slobodan Exp $
23  */

24
25 package com.lutris.util;
26
27 import java.io.PrintStream JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29
30 /**
31  * RuntimeException used as a base for creating an exception that has a chain
32  * of exceptions that lead to the derived exception. Very useful for
33  * interfaces where the implementation exception is not known.
34  */

35 public class ChainedRuntimeException extends RuntimeException JavaDoc implements ChainedThrowable {
36     private Throwable JavaDoc cause;
37
38     /**
39      * Construct an exception without a specified cause.
40      *
41      * @param msg The message associated with the exception.
42      */

43     public ChainedRuntimeException(String JavaDoc msg) {
44         super(msg);
45         cause = null;
46     }
47
48     /**
49      * Construct an exception with an associated causing exception.
50      *
51      * @param msg The message associated with the exception.
52      * @param cause The error or exception that cause this
53      * exception.
54      */

55     public ChainedRuntimeException(String JavaDoc msg,
56                             Throwable JavaDoc cause) {
57         super(msg);
58         this.cause = cause;
59     }
60
61     /**
62      * Construct an exception from a causing exception.
63      *
64      * @param cause The error or exception that cause this
65      * exception. The message will be take be this object's
66      * messasge.
67      */

68     public ChainedRuntimeException(Throwable JavaDoc cause) {
69         super(ChainedThrowableUtil.makeMessage(cause));
70         this.cause = cause;
71     }
72
73     /**
74      * Return the message associated with this exception. If causes
75      * are included, they will be appended to the message.
76      */

77     public String JavaDoc getMessage() {
78         return ChainedThrowableUtil.getMessage(this, super.getMessage());
79     }
80
81     /**
82      * Get the causing exception associated with this exception.
83      * @return The causing exception or null if no cause is specified.
84      */

85     public Throwable JavaDoc getCause() {
86         return cause;
87     }
88
89     /**
90      * Prints this ChainedRuntimeException and its backtrace, and the causes
91      * and their stack traces to the standard error stream.
92      */

93     public void printStackTrace() {
94         super.printStackTrace();
95         ChainedThrowableUtil.printCauseTrace(this);
96     }
97
98     /**
99      * Prints this ChainedRuntimeException and its backtrace, and the causes
100      * and their stack traces to the e specified print stream.
101      */

102     public void printStackTrace(PrintStream JavaDoc s) {
103         super.printStackTrace(s);
104         ChainedThrowableUtil.printCauseTrace(this, s);
105     }
106
107     /**
108      * Prints this ChainedRuntimeException and its backtrace, and the causes
109      * and their stack traces to the e specified print writer.
110      */

111     public void printStackTrace(PrintWriter JavaDoc s) {
112         super.printStackTrace(s);
113         ChainedThrowableUtil.printCauseTrace(this, s);
114     }
115 }
116
Popular Tags