01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 org.springframework.web.util;
18:
19: import javax.servlet.ServletException;
20:
21: import org.springframework.core.NestedExceptionUtils;
22:
23: /**
24: * Subclass of ServletException that properly handles a root cause in terms
25: * of message and stacktrace, just like NestedChecked/RuntimeException does.
26: * Note that the plain ServletException doesn't expose its root cause at all,
27: * neither in the exception message nor in printed stack traces!
28: *
29: * <p>The similarity between this class and the NestedChecked/RuntimeException
30: * class is unavoidable, as this class needs to derive from ServletException
31: * and cannot derive from NestedCheckedException.
32: *
33: * @author Juergen Hoeller
34: * @since 1.2.5
35: * @see #getMessage
36: * @see #printStackTrace
37: * @see org.springframework.core.NestedCheckedException
38: * @see org.springframework.core.NestedRuntimeException
39: */
40: public class NestedServletException extends ServletException {
41:
42: /** Use serialVersionUID from Spring 1.2 for interoperability */
43: private static final long serialVersionUID = -5292377985529381145L;
44:
45: /**
46: * Construct a <code>NestedServletException</code> with the specified detail message.
47: * @param msg the detail message
48: */
49: public NestedServletException(String msg) {
50: super (msg);
51: }
52:
53: /**
54: * Construct a <code>NestedServletException</code> with the specified detail message
55: * and nested exception.
56: * @param msg the detail message
57: * @param cause the nested exception
58: */
59: public NestedServletException(String msg, Throwable cause) {
60: super (msg, cause);
61: // Set JDK 1.4 exception chain cause if not done by ServletException class already
62: // (this differs between Servlet API versions).
63: if (getCause() == null) {
64: initCause(cause);
65: }
66: }
67:
68: /**
69: * Return the detail message, including the message from the nested exception
70: * if there is one.
71: */
72: public String getMessage() {
73: return NestedExceptionUtils.buildMessage(super.getMessage(),
74: getCause());
75: }
76:
77: }
|