1 25 26 27 package org.enhydra.dods.exceptions; 28 29 import java.io.*; 30 31 32 35 public class DodsBaseExceptionUtil { 39 40 48 private DodsBaseExceptionUtil () { 49 } 50 51 55 public static String makeMessage (Throwable cause) { 59 String causeMsg = cause.getMessage(); 65 if (causeMsg == null) { 66 return cause.getClass().getName(); 67 } 68 else { 69 return causeMsg; 70 } 71 } 72 73 76 public static String getMessage (DodsBaseException except, String superMsg) { 80 Throwable cause = except.getCause(); 87 if (cause == null) { 88 return superMsg; 89 } 90 else { 91 String causeMsg = cause.getMessage(); 92 if ((causeMsg == null) || (causeMsg.length() == 0)) { 93 causeMsg = cause.getClass().getName(); 94 } 95 return superMsg + ": " + causeMsg; 96 } 97 } 98 99 106 private static void printChainedCauses (Throwable cause, PrintWriter out) { 107 if (cause != null) { 108 out.println("*** Caused by:"); 109 cause.printStackTrace(out); 110 if (cause instanceof DodsBaseException) { 111 } 114 else if (cause instanceof java.awt.print.PrinterIOException ) { 115 printChainedCauses(((java.awt.print.PrinterIOException )cause).getIOException(), 116 out); 117 } 118 else if (cause instanceof java.io.WriteAbortedException ) { 119 printChainedCauses(((java.io.WriteAbortedException )cause).detail, out); 120 } 121 else if (cause instanceof java.lang.ClassNotFoundException ) { 122 printChainedCauses(((java.lang.ClassNotFoundException )cause).getException(), 123 out); 124 } 125 else if (cause instanceof java.lang.ExceptionInInitializerError ) { 126 printChainedCauses(((java.lang.ExceptionInInitializerError )cause).getException(), 127 out); 128 } 129 else if (cause instanceof java.lang.reflect.InvocationTargetException ) { 130 printChainedCauses(((java.lang.reflect.InvocationTargetException )cause).getTargetException(), 131 out); 132 } 133 else if (cause instanceof java.rmi.RemoteException ) { 134 printChainedCauses(((java.rmi.RemoteException )cause).detail, out); 135 } 136 else if (cause instanceof java.rmi.activation.ActivationException ) { 137 printChainedCauses(((java.rmi.activation.ActivationException )cause).detail, 138 out); 139 } 140 else if (cause instanceof java.rmi.server.ServerCloneException ) { 141 printChainedCauses(((java.rmi.server.ServerCloneException )cause).detail, 142 out); 143 } 144 else if (cause instanceof java.security.PrivilegedActionException ) { 145 printChainedCauses(((java.security.PrivilegedActionException )cause).getException(), 146 out); 147 } 148 else if (cause instanceof java.sql.SQLException ) { 149 printChainedCauses(((java.sql.SQLException )cause).getNextException(), 150 out); 151 } 152 else if (cause instanceof org.xml.sax.SAXException ) { 153 printChainedCauses(((org.xml.sax.SAXException )cause).getException(), 154 out); 155 } 156 } 157 } 158 159 162 public static void printCauseTrace (DodsBaseException except) { 166 PrintWriter pw = new PrintWriter(System.err); 172 printChainedCauses(except.getCause(), pw); 173 pw.flush(); 174 } 175 176 179 public static void printCauseTrace (DodsBaseException except, PrintStream s) { 183 PrintWriter pw = new PrintWriter(s); 190 printChainedCauses(except.getCause(), pw); 191 pw.flush(); 192 } 193 194 197 public static void printCauseTrace (DodsBaseException except, PrintWriter out) { 198 printChainedCauses(except.getCause(), out); 199 out.flush(); 200 } 201 } 202 203 204 205 | Popular Tags |