001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 //
021 // This source code implements specifications defined by the Java
022 // Community Process. In order to remain compliant with the specification
023 // DO NOT add / change / or delete method signatures!
024 //
025
026 package javax.servlet;
027
028 /**
029 * Defines a general exception a servlet can throw when it
030 * encounters difficulty.
031 *
032 * @version $Rev: 467553 $ $Date: 2006-10-24 21:01:51 -0700 (Tue, 24 Oct 2006) $
033 */
034 public class ServletException extends Exception {
035 private Throwable rootCause;
036
037 /**
038 * Constructs a new servlet exception.
039 */
040 public ServletException() {
041 super();
042 }
043
044
045 /**
046 * Constructs a new servlet exception with the
047 * specified message. The message can be written
048 * to the server log and/or displayed for the user.
049 *
050 * @param message a <code>String</code> specifying the text of
051 * the exception message
052 */
053 public ServletException(String message) {
054 super(message);
055 }
056
057 /**
058 * Constructs a new servlet exception when the servlet
059 * needs to throw an exception and include a message
060 * about the "root cause" exception that interfered with its
061 * normal operation, including a description message.
062 *
063 * @param message a <code>String</code> containing
064 * the text of the exception message
065 *
066 * @param rootCause the <code>Throwable</code> exception
067 * that interfered with the servlet's normal operation, making this servlet
068 * exception necessary
069 */
070 public ServletException(String message, Throwable rootCause) {
071 super(message);
072 this.rootCause = rootCause;
073 }
074
075 /**
076 * Constructs a new servlet exception when the servlet
077 * needs to throw an exception and include a message
078 * about the "root cause" exception that interfered with its
079 * normal operation. The exception's message is based on the localized
080 * message of the underlying exception.
081 *
082 * <p>This method calls the <code>getLocalizedMessage</code> method
083 * on the <code>Throwable</code> exception to get a localized exception
084 * message. When subclassing <code>ServletException</code>,
085 * this method can be overridden to create an exception message
086 * designed for a specific locale.
087 *
088 * @param rootCause the <code>Throwable</code> exception
089 * that interfered with the servlet's normal operation, making the
090 * servlet exception necessary
091 */
092 public ServletException(Throwable rootCause) {
093 super(rootCause.getLocalizedMessage());
094 this.rootCause = rootCause;
095 }
096
097 /**
098 * Returns the exception that caused this servlet exception.
099 *
100 * @return the <code>Throwable</code> that caused this servlet exception
101 */
102 public Throwable getRootCause() {
103 return rootCause;
104 }
105 }
106
107
108
109
110