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.jsp;
017
018 /**
019 * A generic exception known to the JSP engine; uncaught
020 * JspExceptions will result in an invocation of the errorpage
021 * machinery.
022 */
023
024 public class JspException extends Exception {
025
026 private Throwable rootCause;
027
028 /**
029 * Construct a JspException.
030 */
031 public JspException() {
032 }
033
034 /**
035 * Constructs a new JSP exception with the
036 * specified message. The message can be written
037 * to the server log and/or displayed for the user.
038 *
039 * @param msg a <code>String</code>
040 * specifying the text of
041 * the exception message
042 *
043 */
044 public JspException(String msg) {
045 super (msg);
046 }
047
048 /**
049 * Constructs a new JSP exception when the JSP
050 * needs to throw an exception and include a message
051 * about the "root cause" exception that interfered with its
052 * normal operation, including a description message.
053 *
054 *
055 * @param message a <code>String</code> containing
056 * the text of the exception message
057 *
058 * @param rootCause the <code>Throwable</code> exception
059 * that interfered with the servlet's
060 * normal operation, making this servlet
061 * exception necessary
062 *
063 */
064
065 public JspException(String message, Throwable rootCause) {
066 super (message);
067 this .rootCause = rootCause;
068 }
069
070 /**
071 * Constructs a new JSP exception when the JSP
072 * needs to throw an exception and include a message
073 * about the "root cause" exception that interfered with its
074 * normal operation. The exception's message is based on the localized
075 * message of the underlying exception.
076 *
077 * <p>This method calls the <code>getLocalizedMessage</code> method
078 * on the <code>Throwable</code> exception to get a localized exception
079 * message. When subclassing <code>JspException</code>,
080 * this method can be overridden to create an exception message
081 * designed for a specific locale.
082 *
083 * @param rootCause the <code>Throwable</code> exception
084 * that interfered with the JSP's
085 * normal operation, making the JSP exception
086 * necessary
087 *
088 */
089
090 public JspException(Throwable rootCause) {
091 super (rootCause.getLocalizedMessage());
092 this .rootCause = rootCause;
093 }
094
095 /**
096 * Returns the exception that caused this JSP exception.
097 *
098 *
099 * @return the <code>Throwable</code>
100 * that caused this JSP exception
101 *
102 */
103
104 public Throwable getRootCause() {
105 return rootCause;
106 }
107 }
|