1 16 package org.apache.commons.collections; 17 18 import java.io.PrintStream ; 19 import java.io.PrintWriter ; 20 21 30 public class FunctorException extends RuntimeException { 31 32 35 private static final boolean JDK_SUPPORTS_NESTED; 36 37 static { 38 boolean flag = false; 39 try { 40 Throwable .class.getDeclaredMethod("getCause", new Class [0]); 41 flag = true; 42 } catch (NoSuchMethodException ex) { 43 flag = false; 44 } 45 JDK_SUPPORTS_NESTED = flag; 46 } 47 48 51 private final Throwable rootCause; 52 53 57 public FunctorException() { 58 super(); 59 this.rootCause = null; 60 } 61 62 68 public FunctorException(String msg) { 69 super(msg); 70 this.rootCause = null; 71 } 72 73 80 public FunctorException(Throwable rootCause) { 81 super((rootCause == null ? null : rootCause.getMessage())); 82 this.rootCause = rootCause; 83 } 84 85 93 public FunctorException(String msg, Throwable rootCause) { 94 super(msg); 95 this.rootCause = rootCause; 96 } 97 98 103 public Throwable getCause() { 104 return rootCause; 105 } 106 107 110 public void printStackTrace() { 111 printStackTrace(System.err); 112 } 113 114 119 public void printStackTrace(PrintStream out) { 120 synchronized (out) { 121 PrintWriter pw = new PrintWriter (out, false); 122 printStackTrace(pw); 123 pw.flush(); 125 } 126 } 127 128 133 public void printStackTrace(PrintWriter out) { 134 synchronized (out) { 135 super.printStackTrace(out); 136 if (rootCause != null && JDK_SUPPORTS_NESTED == false) { 137 out.print("Caused by: "); 138 rootCause.printStackTrace(out); 139 } 140 } 141 } 142 143 } 144 | Popular Tags |