1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package javax.servlet;
17
18
19 /**
20 * Defines a general exception a servlet can throw when it
21 * encounters difficulty.
22 *
23 * @author Various
24 * @version $Version$
25 *
26 */
27
28
29 public class ServletException extends Exception {
30
31 private Throwable rootCause;
32
33
34
35
36
37 /**
38 * Constructs a new servlet exception.
39 *
40 */
41
42 public ServletException() {
43 super();
44 }
45
46
47
48
49
50 /**
51 * Constructs a new servlet exception with the
52 * specified message. The message can be written
53 * to the server log and/or displayed for the user.
54 *
55 * @param message a <code>String</code>
56 * specifying the text of
57 * the exception message
58 *
59 */
60
61 public ServletException(String message) {
62 super(message);
63 }
64
65
66
67
68
69 /**
70 * Constructs a new servlet exception when the servlet
71 * needs to throw an exception and include a message
72 * about the "root cause" exception that interfered with its
73 * normal operation, including a description message.
74 *
75 *
76 * @param message a <code>String</code> containing
77 * the text of the exception message
78 *
79 * @param rootCause the <code>Throwable</code> exception
80 * that interfered with the servlet's
81 * normal operation, making this servlet
82 * exception necessary
83 *
84 */
85
86 public ServletException(String message, Throwable rootCause) {
87 super(message);
88 this.rootCause = rootCause;
89 }
90
91
92
93
94
95 /**
96 * Constructs a new servlet exception when the servlet
97 * needs to throw an exception and include a message
98 * about the "root cause" exception that interfered with its
99 * normal operation. The exception's message is based on the localized
100 * message of the underlying exception.
101 *
102 * <p>This method calls the <code>getLocalizedMessage</code> method
103 * on the <code>Throwable</code> exception to get a localized exception
104 * message. When subclassing <code>ServletException</code>,
105 * this method can be overridden to create an exception message
106 * designed for a specific locale.
107 *
108 * @param rootCause the <code>Throwable</code> exception
109 * that interfered with the servlet's
110 * normal operation, making the servlet exception
111 * necessary
112 *
113 */
114
115 public ServletException(Throwable rootCause) {
116 super(rootCause.getLocalizedMessage());
117 this.rootCause = rootCause;
118 }
119
120
121
122
123
124 /**
125 * Returns the exception that caused this servlet exception.
126 *
127 *
128 * @return the <code>Throwable</code>
129 * that caused this servlet exception
130 *
131 */
132
133 public Throwable getRootCause() {
134 return rootCause;
135 }
136 }
137
138
139
140
141