1 25 26 27 package com.lutris.util; 28 29 import java.io.PrintStream ; 30 import java.io.PrintWriter ; 31 32 33 36 public class ChainedThrowableUtil { 40 41 49 private ChainedThrowableUtil () { 50 } 51 52 56 public static String makeMessage (Throwable cause) { 60 String causeMsg = cause.getMessage(); 66 if (causeMsg == null) { 67 return cause.getClass().getName(); 68 } 69 else { 70 return causeMsg; 71 } 72 } 73 74 77 public static String getMessage (ChainedThrowable except, String superMsg) { 81 Throwable cause = except.getCause(); 88 if (cause == null) { 89 return superMsg; 90 } 91 else { 92 String causeMsg = cause.getMessage(); 93 if ((causeMsg == null) || (causeMsg.length() == 0)) { 94 causeMsg = cause.getClass().getName(); 95 } 96 return superMsg + ": " + causeMsg; 97 } 98 } 99 100 107 private static void printChainedCauses (Throwable cause, PrintWriter out) { 108 if (cause != null) { 109 out.println("*** Caused by:"); 110 cause.printStackTrace(out); 111 if (cause instanceof ChainedThrowable) { 112 } 115 else if (cause instanceof java.awt.print.PrinterIOException ) { 116 printChainedCauses(((java.awt.print.PrinterIOException )cause).getIOException(), 117 out); 118 } 119 else if (cause instanceof java.io.WriteAbortedException ) { 120 printChainedCauses(((java.io.WriteAbortedException )cause).detail, out); 121 } 122 else if (cause instanceof java.lang.ClassNotFoundException ) { 123 printChainedCauses(((java.lang.ClassNotFoundException )cause).getException(), 124 out); 125 } 126 else if (cause instanceof java.lang.ExceptionInInitializerError ) { 127 printChainedCauses(((java.lang.ExceptionInInitializerError )cause).getException(), 128 out); 129 } 130 else if (cause instanceof java.lang.reflect.InvocationTargetException ) { 131 printChainedCauses(((java.lang.reflect.InvocationTargetException )cause).getTargetException(), 132 out); 133 } 134 else if (cause instanceof java.rmi.RemoteException ) { 135 printChainedCauses(((java.rmi.RemoteException )cause).detail, out); 136 } 137 else if (cause instanceof java.rmi.activation.ActivationException ) { 138 printChainedCauses(((java.rmi.activation.ActivationException )cause).detail, 139 out); 140 } 141 else if (cause instanceof java.rmi.server.ServerCloneException ) { 142 printChainedCauses(((java.rmi.server.ServerCloneException )cause).detail, 143 out); 144 } 145 else if (cause instanceof java.security.PrivilegedActionException ) { 146 printChainedCauses(((java.security.PrivilegedActionException )cause).getException(), 147 out); 148 } 149 else if (cause instanceof java.sql.SQLException ) { 150 printChainedCauses(((java.sql.SQLException )cause).getNextException(), 151 out); 152 } 153 else if (cause instanceof org.xml.sax.SAXException ) { 154 printChainedCauses(((org.xml.sax.SAXException )cause).getException(), 155 out); 156 } 157 } 158 } 159 160 163 public static void printCauseTrace (ChainedThrowable except) { 167 PrintWriter pw = new PrintWriter (System.err); 173 printChainedCauses(except.getCause(), pw); 174 pw.flush(); 175 } 176 177 180 public static void printCauseTrace (ChainedThrowable except, PrintStream s) { 184 PrintWriter pw = new PrintWriter (s); 191 printChainedCauses(except.getCause(), pw); 192 pw.flush(); 193 } 194 195 198 public static void printCauseTrace (ChainedThrowable except, PrintWriter out) { 199 printChainedCauses(except.getCause(), out); 200 out.flush(); 201 } 202 } 203 204 205 206 | Popular Tags |