1 13 package info.magnolia.cms.core; 14 15 import java.io.PrintStream ; 16 import java.io.PrintWriter ; 17 18 19 24 public abstract class BaseException extends Exception { 25 26 29 private static final long serialVersionUID = 222L; 30 31 34 protected Throwable rootCause; 35 36 40 public BaseException(String message) { 41 super(message); 42 } 43 44 49 public BaseException(String message, Throwable rootCause) { 50 super(message); 51 this.rootCause = rootCause; 52 } 53 54 58 public BaseException(Throwable rootCause) { 59 this.rootCause = rootCause; 60 } 61 62 65 public String getMessage() { 66 String message = super.getMessage(); 67 if (rootCause == null) { 68 return message; 69 } 70 71 String rootMessage = rootCause.getMessage(); 72 return message != null ? message + ": " + rootMessage : rootMessage; 74 } 75 76 79 public String getLocalizedMessage() { 80 String message = super.getLocalizedMessage(); 81 if (rootCause == null) { 82 return message; 83 } 84 85 String rootMessage = rootCause.getLocalizedMessage(); 86 return message != null ? message + ": " + rootMessage : rootMessage; 88 } 89 90 93 public Throwable getCause() { 94 return rootCause; 95 } 96 97 100 public void printStackTrace() { 101 printStackTrace(System.err); 102 } 103 104 107 public void printStackTrace(PrintStream s) { 108 synchronized (s) { 109 super.printStackTrace(s); 110 if (rootCause != null) { 111 rootCause.printStackTrace(s); 112 } 113 } 114 } 115 116 119 public void printStackTrace(PrintWriter s) { 120 synchronized (s) { 121 super.printStackTrace(s); 122 if (rootCause != null) { 123 rootCause.printStackTrace(s); 124 } 125 } 126 } 127 } 128 | Popular Tags |