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