KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > plugins > PluginAssertionFailure


1 /* $Id: PluginAssertionFailure.java 155412 2005-02-26 12:58:36Z dirkv $
2  *
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.commons.digester.plugins;
19
20 /**
21  * Thrown when a bug is detected in the plugins code.
22  * <p>
23  * This class is intended to be used in assertion statements, similar to
24  * the way that java 1.4's native assertion mechanism is used. However there
25  * is a difference: when a java 1.4 assertion fails, an AssertionError
26  * is thrown, which is a subclass of Error; here, the PluginAssertionFailure
27  * class extends RuntimeException rather than Error.
28  * <p>
29  * This difference in design is because throwing Error objects is not
30  * good in a container-based architecture.
31  * <p>
32  * Example:
33  * <pre>
34  * if (impossibleCondition) {
35  * throw new PluginAssertionFailure(
36  * "internal error: impossible condition is true");
37  * }
38  * </pre>
39  * <p>
40  * Note that PluginAssertionFailure should <i>not</i> be thrown when user
41  * input is bad, or when code external to the Digester module passes invalid
42  * parameters to a plugins method. It should be used only in checks for
43  * problems which indicate internal bugs within the plugins module.
44  *
45  * @since 1.6
46  */

47 public class PluginAssertionFailure extends RuntimeException JavaDoc {
48
49     private Throwable JavaDoc cause = null;
50
51     /**
52      * @param cause underlying exception that caused this to be thrown
53      */

54     public PluginAssertionFailure(Throwable JavaDoc cause) {
55         this(cause.getMessage());
56         this.cause = cause;
57     }
58
59     /**
60      * @param msg describes the reason this exception is being thrown.
61      */

62     public PluginAssertionFailure(String JavaDoc msg) {
63         super(msg);
64     }
65
66     /**
67      * @param msg describes the reason this exception is being thrown.
68      * @param cause underlying exception that caused this to be thrown
69      */

70     public PluginAssertionFailure(String JavaDoc msg, Throwable JavaDoc cause) {
71         this(msg);
72         this.cause = cause;
73     }
74 }
75
Popular Tags