1 7 package com.inversoft.util; 8 9 10 import java.util.Iterator ; 11 12 import com.inversoft.error.ErrorList; 13 14 15 25 public class BaseException extends Exception { 26 27 private ErrorList errors = new ErrorList(); 28 29 33 public BaseException() { 34 super(); 35 } 36 37 45 public BaseException(String message) { 46 super(message); 47 errors.addError(message); 48 } 49 50 59 public BaseException(String message, Throwable cause) { 60 super(message, cause); 61 62 if (cause instanceof BaseException) { 63 errors = ((BaseException) cause).getErrors(); 64 } else { 65 errors.addError(message); 66 } 67 } 68 69 75 public BaseException(Throwable cause) { 76 super(cause); 77 78 if (cause instanceof BaseException) { 79 errors = ((BaseException) cause).getErrors(); 80 } else { 81 errors.addError(cause.getMessage()); 82 } 83 } 84 85 92 public BaseException(String message, ErrorList errors) { 93 super(message); 94 this.errors = errors; 95 } 96 97 102 public BaseException(ErrorList errors) { 103 super(); 104 this.errors = errors; 105 } 106 107 108 113 public ErrorList getErrors() { 114 return errors; 115 } 116 117 123 public void setErrors(ErrorList errors) { 124 this.errors = errors; 125 } 126 127 131 public String toString() { 132 StringBuffer buf = new StringBuffer (); 133 134 if (!StringTools.isEmpty(getMessage())) { 135 buf.append(getMessage()); 136 } 137 138 buf.append("\nError list:\n"); 139 Iterator iter = errors.iterator(); 140 while(iter.hasNext()) { 141 buf.append(iter.next().toString()); 142 buf.append("\n"); 143 } 144 145 return buf.toString(); 146 } 147 } 148 | Popular Tags |