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
030: * the exception text
031: */
032:
033: public PortletException(String text) {
034: super (text);
035: }
036:
037: /**
038: * Constructs a new portlet exception when the portlet needs to do
039: * the following:
040: * <ul>
041: * <li>throw an exception
042: * <li>include the "root cause" exception
043: * <li>include a description message
044: * </ul>
045: *
046: * @param text
047: * the exception text
048: * @param cause
049: * the root cause
050: */
051:
052: public PortletException(String text, Throwable cause) {
053: super (text);
054: _cause = cause;
055: // change this when going to jdk1.4: super (text, cause);
056: }
057:
058: /**
059: * Constructs a new portlet exception when the portlet needs to throw an
060: * exception. The exception's message is based on the localized message
061: * of the underlying exception.
062: *
063: * @param cause
064: * the root cause
065: */
066:
067: public PortletException(Throwable cause) {
068: _cause = cause;
069: // change this when going to jdk1.4: super (cause);
070: }
071:
072: /**
073: * Prints the stack trace of this exception to the standard error stream.
074: */
075: public void printStackTrace() {
076: this .printStackTrace(System.err);
077: }
078:
079: /**
080: * Prints the stack trace of this exception to the specified print stream.
081: *
082: * @param out the <code>PrintStream</code> to be used for output
083: */
084: public void printStackTrace(java.io.PrintStream out) {
085: this .printStackTrace(new java.io.PrintWriter(out, true));
086: }
087:
088: /**
089: * Prints the stack trace of this exception to the specified print writer.
090: *
091: * @param out the <code>PrintWriter</code> to be used for output
092: */
093: public void printStackTrace(java.io.PrintWriter out) {
094: super .printStackTrace(out);
095:
096: if (getCause() != null) {
097: out.println();
098: out.print("Nested Exception is ");
099: getCause().printStackTrace(out);
100: }
101: // change this when going tojdk1.4:
102: /*
103: super.printStackTrace(out);
104:
105: if( getRootCause () != null )
106: {
107: out.println();
108: out.print("Nested Exception is ");
109: getRootCause ().printStackTrace(out);
110: }
111: */
112: }
113:
114: /**
115: * Returns the cause of this throwable or <code>null</code> if the
116: * cause is nonexistent or unknown. (The cause is the throwable that
117: * caused this throwable to get thrown.)
118: *
119: * <p>This implementation returns the cause that was supplied via one of
120: * the constructors requiring a <tt>Throwable</tt>.
121: *
122: * @return the cause of this throwable or <code>null</code> if the
123: * cause is nonexistent or unknown.
124: */
125: public Throwable getCause() {
126: return (_cause != null ? _cause : null);
127: }
128:
129: }
|