KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > portlet > PortletException


1 /**
2   * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
3   * All rights reserved.
4   * Use is subject to license terms.
5   */

6
7 package javax.portlet;
8
9
10
11 /**
12  * The <CODE>PortletException</CODE> class defines a general exception
13  * that a portlet can throw when it is unable to perform its operation
14  * successfully.
15  */

16
17 public class PortletException extends java.lang.Exception JavaDoc
18 {
19
20   private Throwable JavaDoc _cause;
21
22
23   /**
24    * Constructs a new portlet exception.
25    */

26
27   public PortletException ()
28   {
29     super();
30   }
31
32   /**
33    * Constructs a new portlet exception with the given text. The
34    * portlet container may use the text write it to a log.
35    *
36    * @param text
37    * the exception text
38    */

39
40   public PortletException (String JavaDoc text)
41   {
42     super (text);
43   }
44
45   /**
46    * Constructs a new portlet exception when the portlet needs to do
47    * the following:
48    * <ul>
49    * <li>throw an exception
50    * <li>include the "root cause" exception
51    * <li>include a description message
52    * </ul>
53    *
54    * @param text
55    * the exception text
56    * @param cause
57    * the root cause
58    */

59   
60   public PortletException (String JavaDoc text, Throwable JavaDoc cause)
61   {
62     super(text);
63     _cause = cause;
64     // change this when going to jdk1.4: super (text, cause);
65
}
66
67   /**
68    * Constructs a new portlet exception when the portlet needs to throw an
69    * exception. The exception's message is based on the localized message
70    * of the underlying exception.
71    *
72    * @param cause
73    * the root cause
74    */

75
76   public PortletException (Throwable JavaDoc cause)
77   {
78     _cause = cause;
79     // change this when going to jdk1.4: super (cause);
80
}
81
82   /**
83    * Prints the stack trace of this exception to the standard error stream.
84    */

85   public void printStackTrace()
86   {
87     this.printStackTrace(System.err);
88   }
89   
90   /**
91    * Prints the stack trace of this exception to the specified print stream.
92    *
93    * @param out the <code>PrintStream</code> to be used for output
94    */

95   public void printStackTrace(java.io.PrintStream JavaDoc out)
96   {
97     this.printStackTrace(new java.io.PrintWriter JavaDoc(out, true));
98   }
99
100   /**
101    * Prints the stack trace of this exception to the specified print writer.
102    *
103    * @param out the <code>PrintWriter</code> to be used for output
104    */

105   public void printStackTrace(java.io.PrintWriter JavaDoc out)
106   {
107     super.printStackTrace(out);
108
109     if( getCause () != null ) {
110       out.println();
111       out.print("Nested Exception is ");
112       getCause ().printStackTrace(out);
113     }
114     // change this when going tojdk1.4:
115
/*
116         super.printStackTrace(out);
117
118         if( getRootCause () != null )
119         {
120             out.println();
121             out.print("Nested Exception is ");
122             getRootCause ().printStackTrace(out);
123         }
124         */

125   }
126
127   /**
128    * Returns the cause of this throwable or <code>null</code> if the
129    * cause is nonexistent or unknown. (The cause is the throwable that
130    * caused this throwable to get thrown.)
131    *
132    * <p>This implementation returns the cause that was supplied via one of
133    * the constructors requiring a <tt>Throwable</tt>.
134    *
135    * @return the cause of this throwable or <code>null</code> if the
136    * cause is nonexistent or unknown.
137    */

138   public Throwable JavaDoc getCause() {
139     return (_cause!=null ? _cause : null);
140   }
141
142 }
143
Popular Tags