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