1
2
3 /*
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5 *
6 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
7 *
8 * Portions Copyright Apache Software Foundation.
9 *
10 * The contents of this file are subject to the terms of either the GNU
11 * General Public License Version 2 only ("GPL") or the Common Development
12 * and Distribution License("CDDL") (collectively, the "License"). You
13 * may not use this file except in compliance with the License. You can obtain
14 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
15 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
16 * language governing permissions and limitations under the License.
17 *
18 * When distributing the software, include this License Header Notice in each
19 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
20 * Sun designates this particular file as subject to the "Classpath" exception
21 * as provided by Sun in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the License
23 * Header, with the fields enclosed by brackets [] replaced by your own
24 * identifying information: "Portions Copyrighted [year]
25 * [name of copyright owner]"
26 *
27 * Contributor(s):
28 *
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41 package javax.servlet;
42
43
44 /**
45 * Defines a general exception a servlet can throw when it
46 * encounters difficulty.
47 *
48 * @author Various
49 */
50
51
52 public class ServletException extends Exception {
53
54 private Throwable rootCause;
55
56
57
58
59
60 /**
61 * Constructs a new servlet exception.
62 *
63 */
64
65 public ServletException() {
66 super();
67 }
68
69
70
71
72
73 /**
74 * Constructs a new servlet exception with the
75 * specified message. The message can be written
76 * to the server log and/or displayed for the user.
77 *
78 * @param message a <code>String</code>
79 * specifying the text of
80 * the exception message
81 *
82 */
83
84 public ServletException(String message) {
85 super(message);
86 }
87
88
89
90
91
92 /**
93 * Constructs a new servlet exception when the servlet
94 * needs to throw an exception and include a message
95 * about the "root cause" exception that interfered with its
96 * normal operation, including a description message.
97 *
98 *
99 * @param message a <code>String</code> containing
100 * the text of the exception message
101 *
102 * @param rootCause the <code>Throwable</code> exception
103 * that interfered with the servlet's
104 * normal operation, making this servlet
105 * exception necessary
106 *
107 */
108
109 public ServletException(String message, Throwable rootCause) {
110 super(message, rootCause);
111 this.rootCause = rootCause;
112 }
113
114
115
116
117
118 /**
119 * Constructs a new servlet exception when the servlet
120 * needs to throw an exception and include a message
121 * about the "root cause" exception that interfered with its
122 * normal operation. The exception's message is based on the localized
123 * message of the underlying exception.
124 *
125 * <p>This method calls the <code>getLocalizedMessage</code> method
126 * on the <code>Throwable</code> exception to get a localized exception
127 * message. When subclassing <code>ServletException</code>,
128 * this method can be overridden to create an exception message
129 * designed for a specific locale.
130 *
131 * @param rootCause the <code>Throwable</code> exception
132 * that interfered with the servlet's
133 * normal operation, making the servlet exception
134 * necessary
135 *
136 */
137
138 public ServletException(Throwable rootCause) {
139 super(rootCause);
140 this.rootCause = rootCause;
141 }
142
143
144
145
146
147 /**
148 * Returns the exception that caused this servlet exception.
149 *
150 *
151 * @return the <code>Throwable</code>
152 * that caused this servlet exception
153 *
154 */
155
156 public Throwable getRootCause() {
157 return rootCause;
158 }
159 }
160
161
162
163
164