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