1 16 package org.apache.commons.lang.exception; 17 18 import java.io.PrintStream ; 19 import java.io.PrintWriter ; 20 21 33 public class NestableRuntimeException extends RuntimeException implements Nestable { 34 35 39 protected NestableDelegate delegate = new NestableDelegate(this); 40 41 45 private Throwable cause = null; 46 47 51 public NestableRuntimeException() { 52 super(); 53 } 54 55 61 public NestableRuntimeException(String msg) { 62 super(msg); 63 } 64 65 72 public NestableRuntimeException(Throwable cause) { 73 super(); 74 this.cause = cause; 75 } 76 77 85 public NestableRuntimeException(String msg, Throwable cause) { 86 super(msg); 87 this.cause = cause; 88 } 89 90 public Throwable getCause() { 91 return cause; 92 } 93 94 101 public String getMessage() { 102 if (super.getMessage() != null) { 103 return super.getMessage(); 104 } else if (cause != null) { 105 return cause.toString(); 106 } else { 107 return null; 108 } 109 } 110 111 public String getMessage(int index) { 112 if (index == 0) { 113 return super.getMessage(); 114 } else { 115 return delegate.getMessage(index); 116 } 117 } 118 119 public String [] getMessages() { 120 return delegate.getMessages(); 121 } 122 123 public Throwable getThrowable(int index) { 124 return delegate.getThrowable(index); 125 } 126 127 public int getThrowableCount() { 128 return delegate.getThrowableCount(); 129 } 130 131 public Throwable [] getThrowables() { 132 return delegate.getThrowables(); 133 } 134 135 public int indexOfThrowable(Class type) { 136 return delegate.indexOfThrowable(type, 0); 137 } 138 139 public int indexOfThrowable(Class type, int fromIndex) { 140 return delegate.indexOfThrowable(type, fromIndex); 141 } 142 143 public void printStackTrace() { 144 delegate.printStackTrace(); 145 } 146 147 public void printStackTrace(PrintStream out) { 148 delegate.printStackTrace(out); 149 } 150 151 public void printStackTrace(PrintWriter out) { 152 delegate.printStackTrace(out); 153 } 154 155 public final void printPartialStackTrace(PrintWriter out) { 156 super.printStackTrace(out); 157 } 158 159 } 160 | Popular Tags |