1. /* $Id: PluginAssertionFailure.java,v 1.8 2004/05/10 06:44:13 skitching Exp $
  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. package org.apache.commons.digester.plugins;
  18. /**
  19. * Thrown when a bug is detected in the plugins code.
  20. * <p>
  21. * This class is intended to be used in assertion statements, similar to
  22. * the way that java 1.4's native assertion mechanism is used. However there
  23. * is a difference: when a java 1.4 assertion fails, an AssertionError
  24. * is thrown, which is a subclass of Error; here, the PluginAssertionFailure
  25. * class extends RuntimeException rather than Error.
  26. * <p>
  27. * This difference in design is because throwing Error objects is not
  28. * good in a container-based architecture.
  29. * <p>
  30. * Example:
  31. * <pre>
  32. * if (impossibleCondition) {
  33. * throw new PluginAssertionFailure(
  34. * "internal error: impossible condition is true");
  35. * }
  36. * </pre>
  37. * <p>
  38. * Note that PluginAssertionFailure should <i>not</i> be thrown when user
  39. * input is bad, or when code external to the Digester module passes invalid
  40. * parameters to a plugins method. It should be used only in checks for
  41. * problems which indicate internal bugs within the plugins module.
  42. *
  43. * @since 1.6
  44. */
  45. public class PluginAssertionFailure extends RuntimeException {
  46. private Throwable cause = null;
  47. /**
  48. * @param cause underlying exception that caused this to be thrown
  49. */
  50. public PluginAssertionFailure(Throwable cause) {
  51. this(cause.getMessage());
  52. this.cause = cause;
  53. }
  54. /**
  55. * @param msg describes the reason this exception is being thrown.
  56. */
  57. public PluginAssertionFailure(String msg) {
  58. super(msg);
  59. }
  60. /**
  61. * @param msg describes the reason this exception is being thrown.
  62. * @param cause underlying exception that caused this to be thrown
  63. */
  64. public PluginAssertionFailure(String msg, Throwable cause) {
  65. this(msg);
  66. this.cause = cause;
  67. }
  68. }