1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.struts.tiles;
24
25
26 /**
27 * Root class for all Tiles-exceptions.
28 */
29 public class TilesException extends Exception
30 {
31
32
33 /**
34 * Any "wrapped" exception will be exposed when this is serialized.
35 * @serial
36 */
37 private Exception exception;
38 /**
39 * Constructor.
40 */
41 public TilesException()
42 {
43 super();
44 this.exception = null;
45 }
46
47 /**
48 * Constructor.
49 * @param message The error or warning message.
50 */
51 public TilesException(String message)
52 {
53 super(message);
54 this.exception = null;
55 }
56
57
58 /**
59 * Create a new <code>TilesException</code> wrapping an existing exception.
60 *
61 * <p>The existing exception will be embedded in the new
62 * one, and its message will become the default message for
63 * the TilesException.</p>
64 *
65 * @param e The exception to be wrapped.
66 */
67 public TilesException(Exception e)
68 {
69 super();
70 this.exception = e;
71 }
72
73
74 /**
75 * Create a new <code>TilesException</code> from an existing exception.
76 *
77 * <p>The existing exception will be embedded in the new
78 * one, but the new exception will have its own message.</p>
79 *
80 * @param message The detail message.
81 * @param e The exception to be wrapped.
82 */
83 public TilesException(String message, Exception e)
84 {
85 super(message);
86 this.exception = e;
87 }
88
89
90 /**
91 * Return a detail message for this exception.
92 *
93 * <p>If there is a embedded exception, and if the TilesException
94 * has no detail message of its own, this method will return
95 * the detail message from the embedded exception.</p>
96 *
97 * @return The error or warning message.
98 */
99 public String getMessage ()
100 {
101 String message = super.getMessage ();
102
103 if (message == null && exception != null) {
104 return exception.getMessage();
105 } else {
106 return message;
107 }
108 }
109
110
111 /**
112 * Return the embedded exception, if any.
113 *
114 * @return The embedded exception, or <code>null</code> if there is none.
115 */
116 public Exception getException ()
117 {
118 return exception;
119 }
120
121 }