1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.util.exception;
21
22
23 import java.io.PrintStream;
24 import java.io.PrintWriter;
25
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Iterator;
29
30
31
32
33
34
35
36 public class RuntimeMultiException extends RuntimeException
37 {
38
39 private static final long serialVersionUID = 8582253398936366771L;
40
41
42 private Collection<Throwable> nestedExceptions = new ArrayList<Throwable>();
43
44
45
46
47
48 public RuntimeMultiException()
49 {
50 super();
51 }
52
53
54
55
56
57
58
59 public RuntimeMultiException( String message )
60 {
61 super( message );
62 }
63
64
65
66
67
68
69
70 public RuntimeMultiException( String message, Throwable t )
71 {
72 super( message );
73 nestedExceptions.add( t );
74 }
75
76
77
78
79
80
81
82 public Iterator<Throwable> listNestedExceptions()
83 {
84 return nestedExceptions.iterator();
85 }
86
87
88
89
90
91
92
93 public int size()
94 {
95 return nestedExceptions.size();
96 }
97
98
99
100
101
102
103
104 public boolean isEmpty()
105 {
106 return nestedExceptions.isEmpty();
107 }
108
109
110
111
112
113
114
115
116 public void addThrowable( Throwable nested )
117 {
118 nestedExceptions.add( nested );
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133 public void printStackTrace( PrintWriter out )
134 {
135 super.printStackTrace( out );
136
137 out.println( "Nested exceptions to follow:\n" );
138 boolean isFirst = true;
139
140 for ( Throwable throwable : nestedExceptions )
141 {
142 if ( isFirst )
143 {
144 isFirst = false;
145 }
146 else
147 {
148 out.println( "\n\t<<========= Next Nested Exception" + " ========>>\n" );
149 }
150
151 throwable.printStackTrace();
152 }
153
154 out.println( "\n\t<<========= Last Nested Exception" + " ========>>\n" );
155 }
156
157
158
159
160
161
162
163
164
165 public void printStackTrace( PrintStream out )
166 {
167 super.printStackTrace( out );
168
169 out.println( "Nested exceptions to follow:\n" );
170 boolean isFirst = true;
171
172 for ( Throwable throwable : nestedExceptions )
173 {
174 if ( isFirst )
175 {
176 isFirst = false;
177 }
178 else
179 {
180 out.println( "\n\t<<========= Next Nested Exception" + " ========>>\n" );
181 }
182
183 throwable.printStackTrace();
184 }
185
186 out.println( "\n\t<<========= Last Nested Exception" + " ========>>\n" );
187 }
188
189
190
191
192
193
194 public void printStackTrace()
195 {
196 this.printStackTrace( System.err );
197 }
198 }