1 21 22 package org.opensubsystems.core.error; 23 24 import java.io.PrintStream ; 25 import java.io.PrintWriter ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 41 public class OSSMultiException extends OSSException 42 { 43 45 48 private static final long serialVersionUID = -1993344389739792900L; 49 50 53 protected List m_lstExceptions; 54 55 57 60 public OSSMultiException() 61 { 62 super(); 63 } 64 65 70 public OSSMultiException(String message) 71 { 72 super(message); 73 } 74 75 81 public OSSMultiException(String message, Throwable cause) 82 { 83 super(message, cause); 84 add(cause); 85 } 86 87 92 public OSSMultiException(Throwable cause) 93 { 94 super(cause); 95 add(cause); 96 } 97 98 99 105 public OSSMultiException( 106 Throwable first, 107 Throwable second 108 ) 109 { 110 super("Multiple exceptions"); 111 112 m_lstExceptions = new ArrayList (2); 113 add(first); 114 add(second); 115 } 116 117 119 124 public void add( 125 Throwable thr 126 ) 127 { 128 if (m_lstExceptions == null) 129 { 130 m_lstExceptions = new ArrayList (); 131 } 132 133 if (thr instanceof OSSMultiException) 134 { 135 OSSMultiException multiExc = (OSSMultiException)thr; 137 m_lstExceptions.addAll(multiExc.m_lstExceptions); 138 } 139 else 140 { 141 m_lstExceptions.add(thr); 142 } 143 } 144 145 148 public String toString( 149 ) 150 { 151 return this.getClass().getName() + ": " + m_lstExceptions.toString(); 152 } 153 154 157 public void printStackTrace( 158 ) 159 { 160 super.printStackTrace(); 161 162 for (Iterator exc = m_lstExceptions.iterator(); exc.hasNext();) 163 { 164 ((Throwable )exc.next()).printStackTrace(); 165 } 166 } 167 168 171 public void printStackTrace( 172 PrintStream stream 173 ) 174 { 175 super.printStackTrace(stream); 176 177 for (Iterator exc = m_lstExceptions.iterator(); exc.hasNext();) 178 { 179 ((Throwable )exc.next()).printStackTrace(stream); 180 } 181 } 182 183 186 public void printStackTrace( 187 PrintWriter writer 188 ) 189 { 190 super.printStackTrace(writer); 191 192 for (Iterator exc = m_lstExceptions.iterator(); exc.hasNext();) 193 { 194 ((Throwable )exc.next()).printStackTrace(writer); 195 } 196 } 197 198 201 public synchronized Throwable initCause( 202 Throwable thr 203 ) 204 { 205 if (thr != null) 206 { 207 add(thr); 208 } 209 return this; 210 } 211 } 212 | Popular Tags |