1 16 package org.mortbay.util; 17 import java.io.PrintStream ; 18 import java.io.PrintWriter ; 19 import java.util.List ; 20 21 22 23 30 public class MultiException extends Exception 31 { 32 private Object nested; 33 34 35 public MultiException() 36 { 37 super("Multiple exceptions"); 38 } 39 40 41 public void add(Exception e) 42 { 43 if (e instanceof MultiException) 44 { 45 MultiException me = (MultiException)e; 46 for (int i=0;i<LazyList.size(me.nested);i++) 47 nested=LazyList.add(nested,LazyList.get(me.nested,i)); 48 } 49 else 50 nested=LazyList.add(nested,e); 51 } 52 53 54 public int size() 55 { 56 return LazyList.size(nested); 57 } 58 59 60 public List getExceptions() 61 { 62 return LazyList.getList(nested); 63 } 64 65 66 public Exception getException(int i) 67 { 68 return (Exception ) LazyList.get(nested,i); 69 } 70 71 72 78 public void ifExceptionThrow() 79 throws Exception 80 { 81 switch (LazyList.size(nested)) 82 { 83 case 0: 84 break; 85 case 1: 86 throw (Exception )LazyList.get(nested,0); 87 default: 88 throw this; 89 } 90 } 91 92 93 98 public void ifExceptionThrowMulti() 99 throws MultiException 100 { 101 if (LazyList.size(nested)>0) 102 throw this; 103 } 104 105 106 public String toString() 107 { 108 if (LazyList.size(nested)>0) 109 return "org.mortbay.util.MultiException"+ 110 LazyList.getList(nested); 111 return "org.mortbay.util.MultiException[]"; 112 } 113 114 115 public void printStackTrace() 116 { 117 super.printStackTrace(); 118 for (int i=0;i<LazyList.size(nested);i++) 119 ((Throwable )LazyList.get(nested,i)).printStackTrace(); 120 } 121 122 123 124 127 public void printStackTrace(PrintStream out) 128 { 129 super.printStackTrace(out); 130 for (int i=0;i<LazyList.size(nested);i++) 131 ((Throwable )LazyList.get(nested,i)).printStackTrace(out); 132 } 133 134 135 138 public void printStackTrace(PrintWriter out) 139 { 140 super.printStackTrace(out); 141 for (int i=0;i<LazyList.size(nested);i++) 142 ((Throwable )LazyList.get(nested,i)).printStackTrace(out); 143 } 144 145 } 146 | Popular Tags |