1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package com.gargoylesoftware.base.resource;
39
40 import java.io.PrintStream;
41 import java.io.PrintWriter;
42
43 /***
44 * An exception that is thrown by ResourceManager
45 *
46 * @version $Revision: 1.5 $
47 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
48 */
49 public class ResourceException extends RuntimeException {
50
51 private static final long serialVersionUID = 599093006370872479L;
52 private final Throwable enclosedException_;
53
54
55 /***
56 * Create an instance
57 *
58 * @param message The error message
59 */
60 public ResourceException( final String message ) {
61 super( message );
62 if( message == null ) {
63 throw new NullPointerException();
64 }
65 enclosedException_ = null;
66 }
67
68
69 /***
70 * Create an instance
71 *
72 * @param throwable the error that caused this exception
73 */
74 public ResourceException( final Throwable throwable ) {
75 super( throwable.getMessage() );
76 enclosedException_ = throwable;
77 }
78
79
80 /***
81 * Create an instance
82 */
83 protected ResourceException() {
84 enclosedException_ = null;
85 }
86
87
88 /***
89 * Return the enclosed exception
90 *
91 * @return The enclosed exception
92 */
93 public Throwable getEnclosedException() {
94 return enclosedException_;
95 }
96
97
98 /***
99 * Print the stack trace. If this exception contains another exception then
100 * the stack traces for both will be printed.
101 *
102 * @param writer Where the stack trace will be written
103 */
104 public void printStackTrace( final PrintWriter writer ) {
105 super.printStackTrace( writer );
106 if( enclosedException_ != null ) {
107 writer.write( "Enclosed exception: " );
108 enclosedException_.printStackTrace( writer );
109 }
110 }
111
112
113 /***
114 * Print the stack trace. If this exception contains another exception then
115 * the stack traces for both will be printed.
116 *
117 * @param stream Where the stack trace will be written
118 */
119 public void printStackTrace( final PrintStream stream ) {
120 super.printStackTrace( stream );
121 if( enclosedException_ != null ) {
122 stream.print( "Enclosed exception: " );
123 enclosedException_.printStackTrace( stream );
124 }
125 }
126 }
127