1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.util;
20 import java.io.PrintStream;
21 import java.io.PrintWriter;
22 import java.util.List;
23
24
25
26
27
28
29
30
31
32 @SuppressWarnings("serial")
33 public class MultiException extends Exception
34 {
35 private Object nested;
36
37
38 public MultiException()
39 {
40 super("Multiple exceptions");
41 }
42
43
44 public void add(Throwable e)
45 {
46 if (e instanceof MultiException)
47 {
48 MultiException me = (MultiException)e;
49 for (int i=0;i<LazyList.size(me.nested);i++)
50 nested=LazyList.add(nested,LazyList.get(me.nested,i));
51 }
52 else
53 nested=LazyList.add(nested,e);
54 }
55
56
57 public int size()
58 {
59 return LazyList.size(nested);
60 }
61
62
63 public List<Throwable> getThrowables()
64 {
65 return LazyList.getList(nested);
66 }
67
68
69 public Throwable getThrowable(int i)
70 {
71 return (Throwable) LazyList.get(nested,i);
72 }
73
74
75
76
77
78
79
80
81 public void ifExceptionThrow()
82 throws Exception
83 {
84 switch (LazyList.size(nested))
85 {
86 case 0:
87 break;
88 case 1:
89 Throwable th=(Throwable)LazyList.get(nested,0);
90 if (th instanceof Error)
91 throw (Error)th;
92 if (th instanceof Exception)
93 throw (Exception)th;
94 default:
95 throw this;
96 }
97 }
98
99
100
101
102
103
104
105
106
107
108 public void ifExceptionThrowRuntime()
109 throws Error
110 {
111 switch (LazyList.size(nested))
112 {
113 case 0:
114 break;
115 case 1:
116 Throwable th=(Throwable)LazyList.get(nested,0);
117 if (th instanceof Error)
118 throw (Error)th;
119 else if (th instanceof RuntimeException)
120 throw (RuntimeException)th;
121 else
122 throw new RuntimeException(th);
123 default:
124 throw new RuntimeException(this);
125 }
126 }
127
128
129
130
131
132
133
134 public void ifExceptionThrowMulti()
135 throws MultiException
136 {
137 if (LazyList.size(nested)>0)
138 throw this;
139 }
140
141
142 @Override
143 public String toString()
144 {
145 if (LazyList.size(nested)>0)
146 return MultiException.class.getSimpleName()+
147 LazyList.getList(nested);
148 return MultiException.class.getSimpleName()+"[]";
149 }
150
151
152 @Override
153 public void printStackTrace()
154 {
155 super.printStackTrace();
156 for (int i=0;i<LazyList.size(nested);i++)
157 ((Throwable)LazyList.get(nested,i)).printStackTrace();
158 }
159
160
161
162
163
164
165 @Override
166 public void printStackTrace(PrintStream out)
167 {
168 super.printStackTrace(out);
169 for (int i=0;i<LazyList.size(nested);i++)
170 ((Throwable)LazyList.get(nested,i)).printStackTrace(out);
171 }
172
173
174
175
176
177 @Override
178 public void printStackTrace(PrintWriter out)
179 {
180 super.printStackTrace(out);
181 for (int i=0;i<LazyList.size(nested);i++)
182 ((Throwable)LazyList.get(nested,i)).printStackTrace(out);
183 }
184
185 }