001 /* $Id: PluginAssertionFailure.java 476205 2006-11-17 16:43:10Z dennisl $ 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.commons.digester.plugins; 020 021 /** 022 * Thrown when a bug is detected in the plugins code. 023 * <p> 024 * This class is intended to be used in assertion statements, similar to 025 * the way that java 1.4's native assertion mechanism is used. However there 026 * is a difference: when a java 1.4 assertion fails, an AssertionError 027 * is thrown, which is a subclass of Error; here, the PluginAssertionFailure 028 * class extends RuntimeException rather than Error. 029 * <p> 030 * This difference in design is because throwing Error objects is not 031 * good in a container-based architecture. 032 * <p> 033 * Example: 034 * <pre> 035 * if (impossibleCondition) { 036 * throw new PluginAssertionFailure( 037 * "internal error: impossible condition is true"); 038 * } 039 * </pre> 040 * <p> 041 * Note that PluginAssertionFailure should <i>not</i> be thrown when user 042 * input is bad, or when code external to the Digester module passes invalid 043 * parameters to a plugins method. It should be used only in checks for 044 * problems which indicate internal bugs within the plugins module. 045 * 046 * @since 1.6 047 */ 048 public class PluginAssertionFailure extends RuntimeException { 049 050 private Throwable cause = null; 051 052 /** 053 * @param cause underlying exception that caused this to be thrown 054 */ 055 public PluginAssertionFailure(Throwable cause) { 056 this(cause.getMessage()); 057 this.cause = cause; 058 } 059 060 /** 061 * @param msg describes the reason this exception is being thrown. 062 */ 063 public PluginAssertionFailure(String msg) { 064 super(msg); 065 } 066 067 /** 068 * @param msg describes the reason this exception is being thrown. 069 * @param cause underlying exception that caused this to be thrown 070 */ 071 public PluginAssertionFailure(String msg, Throwable cause) { 072 this(msg); 073 this.cause = cause; 074 } 075 076 /** 077 * Return the cause of this exception (if any) as specified in the 078 * exception constructor. 079 * 080 * @since 1.8 081 */ 082 public Throwable getCause() { 083 return cause; 084 } 085 }