You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HPSFRuntimeException.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hpsf;
  16. import java.io.PrintStream;
  17. import java.io.PrintWriter;
  18. /**
  19. * <p>This exception is the superclass of all other unchecked
  20. * exceptions thrown in this package. It supports a nested "reason"
  21. * throwable, i.e. an exception that caused this one to be thrown.</p>
  22. *
  23. * @author Rainer Klute <a
  24. * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  25. */
  26. public class HPSFRuntimeException extends RuntimeException
  27. {
  28. /** <p>The underlying reason for this exception - may be
  29. * <code>null</code>.</p> */
  30. private Throwable reason;
  31. /**
  32. * <p>Creates a new {@link HPSFRuntimeException}.</p>
  33. */
  34. public HPSFRuntimeException()
  35. {
  36. super();
  37. }
  38. /**
  39. * <p>Creates a new {@link HPSFRuntimeException} with a message
  40. * string.</p>
  41. *
  42. * @param msg The message string.
  43. */
  44. public HPSFRuntimeException(final String msg)
  45. {
  46. super(msg);
  47. }
  48. /**
  49. * <p>Creates a new {@link HPSFRuntimeException} with a
  50. * reason.</p>
  51. *
  52. * @param reason The reason, i.e. a throwable that indirectly
  53. * caused this exception.
  54. */
  55. public HPSFRuntimeException(final Throwable reason)
  56. {
  57. super();
  58. this.reason = reason;
  59. }
  60. /**
  61. * <p>Creates a new {@link HPSFRuntimeException} with a message
  62. * string and a reason.</p>
  63. *
  64. * @param msg The message string.
  65. * @param reason The reason, i.e. a throwable that indirectly
  66. * caused this exception.
  67. */
  68. public HPSFRuntimeException(final String msg, final Throwable reason)
  69. {
  70. super(msg);
  71. this.reason = reason;
  72. }
  73. /**
  74. * <p>Returns the {@link Throwable} that caused this exception to
  75. * be thrown or <code>null</code> if there was no such {@link
  76. * Throwable}.</p>
  77. *
  78. * @return The reason
  79. */
  80. public Throwable getReason()
  81. {
  82. return reason;
  83. }
  84. /**
  85. * @see Throwable#printStackTrace()
  86. */
  87. public void printStackTrace()
  88. {
  89. printStackTrace(System.err);
  90. }
  91. /**
  92. * @see Throwable#printStackTrace(java.io.PrintStream)
  93. */
  94. public void printStackTrace(final PrintStream p)
  95. {
  96. final Throwable reason = getReason();
  97. super.printStackTrace(p);
  98. if (reason != null)
  99. {
  100. p.println("Caused by:");
  101. reason.printStackTrace(p);
  102. }
  103. }
  104. /**
  105. * @see Throwable#printStackTrace(java.io.PrintWriter)
  106. */
  107. public void printStackTrace(final PrintWriter p)
  108. {
  109. final Throwable reason = getReason();
  110. super.printStackTrace(p);
  111. if (reason != null)
  112. {
  113. p.println("Caused by:");
  114. reason.printStackTrace(p);
  115. }
  116. }
  117. }