1 28 package net.sf.jasperreports.engine; 29 30 import java.io.PrintStream ; 31 import java.io.PrintWriter ; 32 33 34 39 public class JRException extends Exception 40 { 41 42 45 private static boolean isJre14orLater = true; 46 47 static 48 { 49 isJre14orLater = true; 50 try 51 { 52 Exception .class.getMethod("getCause", (Class [])null); 53 } 54 catch (NoSuchMethodException e) 55 { 56 isJre14orLater = false; 57 } 58 } 59 60 63 private Throwable nestedThrowable = null; 64 65 66 69 public JRException(String message) 70 { 71 super(message); 72 } 73 74 75 78 public JRException(Throwable t) 79 { 80 this(t.toString(), t); 81 } 82 83 84 87 public JRException(String message, Throwable t) 88 { 89 super(message); 90 91 nestedThrowable = t; 92 } 93 94 95 98 public Throwable getCause() 99 { 100 return nestedThrowable; 101 } 102 103 104 107 public void printStackTrace() 108 { 109 if (!isJre14orLater && nestedThrowable != null) 110 { 111 nestedThrowable.printStackTrace(); 112 System.err.println("\nNested by:"); 113 } 114 115 super.printStackTrace(); 116 } 117 118 119 122 public void printStackTrace(PrintStream s) 123 { 124 if (!isJre14orLater && nestedThrowable != null) 125 { 126 nestedThrowable.printStackTrace(s); 127 s.println("\nNested by:"); 128 } 129 130 super.printStackTrace(s); 131 } 132 133 134 137 public void printStackTrace(PrintWriter s) 138 { 139 if (!isJre14orLater && nestedThrowable != null) 140 { 141 nestedThrowable.printStackTrace(s); 142 s.println("\nNested by:"); 143 } 144 145 super.printStackTrace(s); 146 } 147 148 149 } 150 | Popular Tags |