1 7 8 package org.dom4j; 9 10 import java.io.PrintStream ; 11 import java.io.PrintWriter ; 12 13 22 public class DocumentException extends Exception { 23 24 private Throwable nestedException; 25 26 public DocumentException() { 27 super("Error occurred in DOM4J application."); 28 } 29 30 public DocumentException(String message) { 31 super(message); 32 } 33 34 public DocumentException(Throwable nestedException) { 35 super(nestedException.getMessage()); 36 this.nestedException = nestedException; 37 } 38 39 public DocumentException(String message, Throwable nestedException) { 40 super(message); 41 this.nestedException = nestedException; 42 } 43 44 public Throwable getNestedException() { 45 return nestedException; 46 } 47 48 public String getMessage() { 49 if (nestedException != null) { 50 return super.getMessage() + " Nested exception: " 51 + nestedException.getMessage(); 52 } else { 53 return super.getMessage(); 54 } 55 } 56 57 public void printStackTrace() { 58 super.printStackTrace(); 59 60 if (nestedException != null) { 61 System.err.print("Nested exception: "); 62 nestedException.printStackTrace(); 63 } 64 } 65 66 public void printStackTrace(PrintStream out) { 67 super.printStackTrace(out); 68 69 if (nestedException != null) { 70 out.println("Nested exception: "); 71 nestedException.printStackTrace(out); 72 } 73 } 74 75 public void printStackTrace(PrintWriter writer) { 76 super.printStackTrace(writer); 77 78 if (nestedException != null) { 79 writer.println("Nested exception: "); 80 nestedException.printStackTrace(writer); 81 } 82 } 83 } 84 85 121 | Popular Tags |