001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hpsf;
019:
020: import java.io.PrintStream;
021: import java.io.PrintWriter;
022:
023: /**
024: * <p>This exception is the superclass of all other unchecked
025: * exceptions thrown in this package. It supports a nested "reason"
026: * throwable, i.e. an exception that caused this one to be thrown.</p>
027: *
028: * @author Rainer Klute <a
029: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
030: * @version $Id: HPSFRuntimeException.java 489730 2006-12-22 19:18:16Z bayard $
031: * @since 2002-02-09
032: */
033: public class HPSFRuntimeException extends RuntimeException {
034:
035: /** <p>The underlying reason for this exception - may be
036: * <code>null</code>.</p> */
037: private Throwable reason;
038:
039: /**
040: * <p>Creates a new {@link HPSFRuntimeException}.</p>
041: */
042: public HPSFRuntimeException() {
043: super ();
044: }
045:
046: /**
047: * <p>Creates a new {@link HPSFRuntimeException} with a message
048: * string.</p>
049: *
050: * @param msg The message string.
051: */
052: public HPSFRuntimeException(final String msg) {
053: super (msg);
054: }
055:
056: /**
057: * <p>Creates a new {@link HPSFRuntimeException} with a
058: * reason.</p>
059: *
060: * @param reason The reason, i.e. a throwable that indirectly
061: * caused this exception.
062: */
063: public HPSFRuntimeException(final Throwable reason) {
064: super ();
065: this .reason = reason;
066: }
067:
068: /**
069: * <p>Creates a new {@link HPSFRuntimeException} with a message
070: * string and a reason.</p>
071: *
072: * @param msg The message string.
073: * @param reason The reason, i.e. a throwable that indirectly
074: * caused this exception.
075: */
076: public HPSFRuntimeException(final String msg, final Throwable reason) {
077: super (msg);
078: this .reason = reason;
079: }
080:
081: /**
082: * <p>Returns the {@link Throwable} that caused this exception to
083: * be thrown or <code>null</code> if there was no such {@link
084: * Throwable}.</p>
085: *
086: * @return The reason
087: */
088: public Throwable getReason() {
089: return reason;
090: }
091:
092: /**
093: * @see Throwable#printStackTrace()
094: */
095: public void printStackTrace() {
096: printStackTrace(System.err);
097: }
098:
099: /**
100: * @see Throwable#printStackTrace(java.io.PrintStream)
101: */
102: public void printStackTrace(final PrintStream p) {
103: final Throwable reason = getReason();
104: super .printStackTrace(p);
105: if (reason != null) {
106: p.println("Caused by:");
107: reason.printStackTrace(p);
108: }
109: }
110:
111: /**
112: * @see Throwable#printStackTrace(java.io.PrintWriter)
113: */
114: public void printStackTrace(final PrintWriter p) {
115: final Throwable reason = getReason();
116: super .printStackTrace(p);
117: if (reason != null) {
118: p.println("Caused by:");
119: reason.printStackTrace(p);
120: }
121: }
122:
123: }
|