1 23 24 package org.enhydra.xml.xmlc.commands; 25 26 import java.io.FileNotFoundException ; 27 import java.io.IOException ; 28 29 import org.enhydra.error.ChainedThrowable; 30 import org.xml.sax.SAXException ; 31 32 35 public class ErrorHandling { 36 37 40 private ErrorHandling() { 41 } 42 43 46 private static void printStackTrace(Throwable except) { 47 except.printStackTrace(); 48 49 while ((except != null) && (except instanceof ChainedThrowable)) { 52 except = ((ChainedThrowable)except).getCause(); 53 } 54 if ((except != null) && (except instanceof SAXException )) { 55 Exception except2 = ((SAXException )except).getException(); 56 if (except2 != null) { 57 printStackTrace(except2); 58 } 59 } 60 } 61 62 69 public static void handleException(Throwable except, 70 boolean verbose) { 71 if (except instanceof ChainedThrowable) { 72 System.err.println("Error: " + except.getMessage()); 73 if (verbose) { 74 printStackTrace(except); 75 } 76 77 Throwable cause = ((ChainedThrowable)except).getCause(); 79 if ((!verbose) && (cause != null) 80 && cause.getClass().getName().startsWith("java.lang.")) { 81 printStackTrace(cause); 82 } 83 } else if ((except instanceof FileNotFoundException ) 84 || (except instanceof IOException )) { 85 System.err.println("Error: " + except.toString()); 86 if (verbose) { 87 printStackTrace(except); 88 } 89 } else { 90 System.err.println("Error: " + except.toString()); 91 printStackTrace(except); 92 } 93 System.exit(1); 94 } 95 } 96 | Popular Tags |