View Javadoc

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