001 /*
002 * Copyright 2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package javax.servlet;
017
018
019 /**
020 * Defines a general exception a servlet can throw when it
021 * encounters difficulty.
022 *
023 * @author Various
024 * @version $Version$
025 *
026 */
027
028
029 public class ServletException extends Exception {
030
031 private Throwable rootCause;
032
033
034
035
036
037 /**
038 * Constructs a new servlet exception.
039 *
040 */
041
042 public ServletException() {
043 super();
044 }
045
046
047
048
049
050 /**
051 * Constructs a new servlet exception with the
052 * specified message. The message can be written
053 * to the server log and/or displayed for the user.
054 *
055 * @param message a <code>String</code>
056 * specifying the text of
057 * the exception message
058 *
059 */
060
061 public ServletException(String message) {
062 super(message);
063 }
064
065
066
067
068
069 /**
070 * Constructs a new servlet exception when the servlet
071 * needs to throw an exception and include a message
072 * about the "root cause" exception that interfered with its
073 * normal operation, including a description message.
074 *
075 *
076 * @param message a <code>String</code> containing
077 * the text of the exception message
078 *
079 * @param rootCause the <code>Throwable</code> exception
080 * that interfered with the servlet's
081 * normal operation, making this servlet
082 * exception necessary
083 *
084 */
085
086 public ServletException(String message, Throwable rootCause) {
087 super(message);
088 this.rootCause = rootCause;
089 }
090
091
092
093
094
095 /**
096 * Constructs a new servlet exception when the servlet
097 * needs to throw an exception and include a message
098 * about the "root cause" exception that interfered with its
099 * 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