1
2
3
4
5
6
7 package org.abraracourcix.alipes.pipes;
8
9 import java.util.ArrayList;
10 import java.util.Collection;
11 import java.util.Iterator;
12
13 import org.abraracourcix.alipes.listeners.ListenerException;
14
15 /***
16 * Can occur if one or more of the multiplexor's listeners throw an exception.
17 * Since any or all of the multiplexor's listeners can throw exceptions during
18 * multiplexing this exception bundles them all up into one.
19 *
20 * @author jdt
21 */
22 public class MultiplexorException extends ListenerException {
23 /***
24 * Underlying exceptions bundled in.
25 */
26 private Collection causes = new ArrayList();
27 /***
28 * Constructor
29 * @param cause root cause
30 */
31 public MultiplexorException(final Throwable cause) {
32 super(cause);
33 causes.add(cause);
34 }
35 /***
36 * Constructor
37 * @param description Description of error
38 * @param cause root cause
39 */
40 public MultiplexorException(final String description, final Throwable cause) {
41 super(description, cause);
42 causes.add(cause);
43 }
44
45 /***
46 * Add a new exception
47 * @param cause yet another cause
48 */
49 public final void addCause(final Throwable cause) {
50 causes.add(cause);
51 }
52 /***
53 * Override to append all enclosed exceptions
54 * @return see below
55 * @see java.lang.Throwable#getMessage()
56 */
57 public final String getMessage() {
58 final StringBuffer buff = new StringBuffer(super.getMessage()+":\n");
59 final Iterator it = causes.iterator();
60 while (it.hasNext()) {
61 final Throwable ex = (Throwable) it.next();
62 buff.append(ex.getMessage()+"\n");
63 }
64 return buff.toString();
65 }
66 }
67
68
69
70
71
72
73
74
75
76
77