View Javadoc

1   /*
2   * Copyright 2004 The Apache Software Foundation
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.apache.org/licenses/LICENSE-2.0
9   *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  package javax.servlet;
17  
18  
19  /**
20   * Defines a general exception a servlet can throw when it
21   * encounters difficulty.
22   *
23   * @author 	Various
24   * @version 	$Version$
25   *
26   */
27  
28  
29  public class ServletException extends Exception {
30  
31      private Throwable rootCause;
32  
33  
34  
35  
36  
37      /**
38       * Constructs a new servlet exception.
39       *
40       */
41  
42      public ServletException() {
43  	super();
44      }
45      
46     
47  
48      
49  
50      /**
51       * Constructs a new servlet exception with the
52       * specified message. The message can be written 
53       * to the server log and/or displayed for the user. 
54       *
55       * @param message 		a <code>String</code> 
56       *				specifying the text of 
57       *				the exception message
58       *
59       */
60  
61      public ServletException(String message) {
62  	super(message);
63      }
64      
65     
66     
67      
68  
69      /**
70       * Constructs a new servlet exception when the servlet 
71       * needs to throw an exception and include a message 
72       * about the "root cause" exception that interfered with its 
73       * normal operation, including a description message.
74       *
75       *
76       * @param message 		a <code>String</code> containing 
77       *				the text of the exception message
78       *
79       * @param rootCause		the <code>Throwable</code> exception 
80       *				that interfered with the servlet's
81       *				normal operation, making this servlet
82       *				exception necessary
83       *
84       */
85      
86      public ServletException(String message, Throwable rootCause) {
87  	super(message);
88  	this.rootCause = rootCause;
89      }
90  
91  
92  
93  
94  
95      /**
96       * Constructs a new servlet exception when the servlet 
97       * needs to throw an exception and include a message
98       * about the "root cause" exception that interfered with its
99       * normal operation.  The exception's message is based on the localized
100      * message of the underlying exception.
101      *
102      * <p>This method calls the <code>getLocalizedMessage</code> method
103      * on the <code>Throwable</code> exception to get a localized exception
104      * message. When subclassing <code>ServletException</code>, 
105      * this method can be overridden to create an exception message 
106      * designed for a specific locale.
107      *
108      * @param rootCause 	the <code>Throwable</code> exception
109      * 				that interfered with the servlet's
110      *				normal operation, making the servlet exception
111      *				necessary
112      *
113      */
114 
115     public ServletException(Throwable rootCause) {
116 	super(rootCause.getLocalizedMessage());
117 	this.rootCause = rootCause;
118     }
119   
120   
121  
122  
123     
124     /**
125      * Returns the exception that caused this servlet exception.
126      *
127      *
128      * @return			the <code>Throwable</code> 
129      *				that caused this servlet exception
130      *
131      */
132     
133     public Throwable getRootCause() {
134 	return rootCause;
135     }
136 }
137 
138 
139 
140 
141