001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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 package javax.servlet.jsp; 018 019 /** 020 * A generic exception known to the JSP engine; uncaught 021 * JspExceptions will result in an invocation of the errorpage 022 * machinery. 023 */ 024 025 public class JspException extends Exception { 026 027 private Throwable rootCause; 028 029 030 /** 031 * Construct a JspException. 032 */ 033 public JspException() { 034 } 035 036 037 /** 038 * Constructs a new JSP exception with the 039 * specified message. The message can be written 040 * to the server log and/or displayed for the user. 041 * 042 * @param msg a <code>String</code> 043 * specifying the text of 044 * the exception message 045 * 046 */ 047 public JspException(String msg) { 048 super(msg); 049 } 050 051 052 /** 053 * Constructs a new JSP exception when the JSP 054 * needs to throw an exception and include a message 055 * about the "root cause" exception that interfered with its 056 * normal operation, including a description message. 057 * 058 * 059 * @param message a <code>String</code> containing 060 * the text of the exception message 061 * 062 * @param rootCause the <code>Throwable</code> exception 063 * that interfered with the servlet's 064 * normal operation, making this servlet 065 * exception necessary 066 * 067 */ 068 069 public JspException(String message, Throwable rootCause) { 070 super(message); 071 this.rootCause = rootCause; 072 } 073 074 075 /** 076 * Constructs a new JSP exception when the JSP 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>JspException</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 JSP's 090 * normal operation, making the JSP exception 091 * necessary 092 * 093 */ 094 095 public JspException(Throwable rootCause) { 096 super(rootCause.getLocalizedMessage()); 097 this.rootCause = rootCause; 098 } 099 100 101 /** 102 * Returns the exception that caused this JSP exception. 103 * 104 * 105 * @return the <code>Throwable</code> 106 * that caused this JSP exception 107 * 108 */ 109 110 public Throwable getRootCause() { 111 return rootCause; 112 } 113 }