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