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