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.objectstore;
39
40 import java.io.PrintStream;
41 import java.io.PrintWriter;
42
43 /***
44 * Thrown when an error occuring during the processing of an object store.
45 *
46 * @version $Revision: 1.5 $
47 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
48 */
49 public class ObjectStoreException extends RuntimeException {
50
51 private static final long serialVersionUID = 3689038830840948053L;
52 private final Exception exception_;
53
54
55 /***
56 * Create an instance
57 *
58 * @param message The text of the exception
59 */
60 public ObjectStoreException( final String message ) {
61 super( message );
62 exception_ = null;
63 }
64
65
66 /***
67 * Create an instance
68 *
69 * @param e An exception that this exception is enclosing
70 */
71 public ObjectStoreException( final Exception e ) {
72 super( e.toString() );
73 exception_ = e;
74 }
75
76
77 /***
78 * Create an instance
79 *
80 * @param message The text of the exception
81 * @param e An exception that this exception is enclosing
82 */
83 public ObjectStoreException( final String message, final Exception e ) {
84 super( message );
85 exception_ = e;
86 }
87
88
89 /***
90 * Create an instance
91 */
92 protected ObjectStoreException() {
93 exception_ = null;
94 }
95
96
97 /***
98 * Return the enclosed exception
99 *
100 * @return The enclosed exception or null if one was not specified
101 */
102 public Exception getException() {
103 return exception_;
104 }
105
106
107 /***
108 * Print the stack trace. If this exception contains another exception then
109 * the stack traces for both will be printed.
110 *
111 * @param writer Where the stack trace will be written
112 */
113 public void printStackTrace( final PrintWriter writer ) {
114 super.printStackTrace( writer );
115 if( exception_ != null ) {
116 writer.write( "Enclosed exception: " );
117 exception_.printStackTrace( writer );
118 }
119 }
120
121
122 /***
123 * Print the stack trace. If this exception contains another exception then
124 * the stack traces for both will be printed.
125 *
126 * @param stream Where the stack trace will be written
127 */
128 public void printStackTrace( final PrintStream stream ) {
129 super.printStackTrace( stream );
130 if( exception_ != null ) {
131 stream.print( "Enclosed exception: " );
132 exception_.printStackTrace( stream );
133 }
134 }
135 }
136