001: /**
002: * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
003: * All rights reserved.
004: * Use is subject to license terms.
005: */package javax.portlet;
006:
007: /**
008: * The <CODE>PortletException</CODE> class defines a general exception
009: * that a portlet can throw when it is unable to perform its operation
010: * successfully.
011: */
012:
013: public class PortletException extends java.lang.Exception {
014:
015: private Throwable _cause;
016:
017: /**
018: * Constructs a new portlet exception.
019: */
020:
021: public PortletException() {
022: super ();
023: }
024:
025: /**
026: * Constructs a new portlet exception with the given text. The
027: * portlet container may use the text write it to a log.
028: *
029: * @param text the exception text
030: */
031:
032: public PortletException(String text) {
033: super (text);
034: }
035:
036: /**
037: * Constructs a new portlet exception when the portlet needs to do
038: * the following:
039: * <ul>
040: * <li>throw an exception
041: * <li>include the "root cause" exception
042: * <li>include a description message
043: * </ul>
044: *
045: * @param text the exception text
046: * @param cause the root cause
047: */
048:
049: public PortletException(String text, Throwable cause) {
050: super (text, cause);
051: _cause = cause;
052: // change this when going to jdk1.4: super (text, cause);
053: }
054:
055: /**
056: * Constructs a new portlet exception when the portlet needs to throw an
057: * exception. The exception's message is based on the localized message
058: * of the underlying exception.
059: *
060: * @param cause the root cause
061: */
062:
063: public PortletException(Throwable cause) {
064: super (cause);
065: _cause = cause;
066: // change this when going to jdk1.4: super (cause);
067: }
068:
069: /**
070: * Prints the stack trace of this exception to the standard error stream.
071: */
072: public void printStackTrace() {
073: this .printStackTrace(System.err);
074: }
075:
076: /**
077: * Prints the stack trace of this exception to the specified print stream.
078: *
079: * @param out the <code>PrintStream</code> to be used for output
080: */
081: public void printStackTrace(java.io.PrintStream out) {
082: this .printStackTrace(new java.io.PrintWriter(out, true));
083: }
084:
085: /**
086: * Prints the stack trace of this exception to the specified print writer.
087: *
088: * @param out the <code>PrintWriter</code> to be used for output
089: */
090: public void printStackTrace(java.io.PrintWriter out) {
091: super .printStackTrace(out);
092:
093: if (getCause() != null) {
094: out.println();
095: out.print("Nested Exception is ");
096: getCause().printStackTrace(out);
097: }
098: // change this when going tojdk1.4:
099: /*
100: super.printStackTrace(out);
101:
102: if( getRootCause () != null )
103: {
104: out.println();
105: out.print("Nested Exception is ");
106: getRootCause ().printStackTrace(out);
107: }
108: */
109: }
110:
111: /**
112: * Returns the cause of this throwable or <code>null</code> if the
113: * cause is nonexistent or unknown. (The cause is the throwable that
114: * caused this throwable to get thrown.)
115: * <p/>
116: * <p>This implementation returns the cause that was supplied via one of
117: * the constructors requiring a <tt>Throwable</tt>.
118: *
119: * @return the cause of this throwable or <code>null</code> if the
120: * cause is nonexistent or unknown.
121: */
122: public Throwable getCause() {
123: return (_cause != null ? _cause : null);
124: }
125:
126: }
|