Michael E. Rodriguez | d8af66f | 2005-12-08 20:55:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1999,2005 The Apache Software Foundation. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package javax.servlet; |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * Defines a general exception a servlet can throw when it |
| 22 | * encounters difficulty. |
| 23 | * |
| 24 | * @author Various |
| 25 | * @version $Version$ |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | public class ServletException extends Exception { |
| 31 | |
| 32 | private Throwable rootCause; |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Constructs a new servlet exception. |
| 40 | * |
| 41 | */ |
| 42 | |
| 43 | public ServletException() { |
| 44 | super(); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * Constructs a new servlet exception with the |
| 53 | * specified message. The message can be written |
| 54 | * to the server log and/or displayed for the user. |
| 55 | * |
| 56 | * @param message a <code>String</code> |
| 57 | * specifying the text of |
| 58 | * the exception message |
| 59 | * |
| 60 | */ |
| 61 | |
| 62 | public ServletException(String message) { |
| 63 | super(message); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * Constructs a new servlet exception when the servlet |
| 72 | * needs to throw an exception and include a message |
| 73 | * about the "root cause" exception that interfered with its |
| 74 | * normal operation, including a description message. |
| 75 | * |
| 76 | * |
| 77 | * @param message a <code>String</code> containing |
| 78 | * the text of the exception message |
| 79 | * |
| 80 | * @param rootCause the <code>Throwable</code> exception |
| 81 | * that interfered with the servlet's |
| 82 | * normal operation, making this servlet |
| 83 | * exception necessary |
| 84 | * |
| 85 | */ |
| 86 | |
| 87 | public ServletException(String message, Throwable rootCause) { |
| 88 | super(message); |
| 89 | this.rootCause = rootCause; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | /** |
| 97 | * Constructs a new servlet exception when the servlet |
| 98 | * needs to throw an exception and include a message |
| 99 | * about the "root cause" exception that interfered with its |
| 100 | * normal operation. The exception's message is based on the localized |
| 101 | * message of the underlying exception. |
| 102 | * |
| 103 | * <p>This method calls the <code>getLocalizedMessage</code> method |
| 104 | * on the <code>Throwable</code> exception to get a localized exception |
| 105 | * message. When subclassing <code>ServletException</code>, |
| 106 | * this method can be overridden to create an exception message |
| 107 | * designed for a specific locale. |
| 108 | * |
| 109 | * @param rootCause the <code>Throwable</code> exception |
| 110 | * that interfered with the servlet's |
| 111 | * normal operation, making the servlet exception |
| 112 | * necessary |
| 113 | * |
| 114 | */ |
| 115 | |
| 116 | public ServletException(Throwable rootCause) { |
| 117 | super(rootCause.getLocalizedMessage()); |
| 118 | this.rootCause = rootCause; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | /** |
| 126 | * Returns the exception that caused this servlet exception. |
| 127 | * |
| 128 | * |
| 129 | * @return the <code>Throwable</code> |
| 130 | * that caused this servlet exception |
| 131 | * |
| 132 | */ |
| 133 | |
| 134 | public Throwable getRootCause() { |
| 135 | return rootCause; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |