1 46 package org.mr.core.util.exceptions; 47 48 import java.io.PrintStream ; 49 import java.io.PrintWriter ; 50 51 58 public class NestedException extends Exception 59 { 60 61 private Throwable m_nestedException; 62 63 public NestedException() { 64 super(); 65 } 66 67 public NestedException(String message) { 68 super(message); 69 } 70 71 public NestedException(String message, Throwable nestedException) { 72 super(message); 73 m_nestedException = nestedException; 74 } 75 76 public Throwable getOriginatingException() { 77 return m_nestedException; 78 } 79 80 85 public String getMessage() { 86 StringBuffer buff = new StringBuffer (); 87 String msg = super.getMessage(); 88 if (msg == null) { 89 msg = ""; 90 } 91 buff.append(msg); 92 if (m_nestedException != null) { 93 buff.append(" Cause: "); 94 buff.append(m_nestedException.getMessage()); 95 } 96 return buff.toString(); 97 } 98 99 105 public void printStackTrace(PrintStream s) { 106 super.printStackTrace(s); 107 if (m_nestedException != null) { 108 s.println("----- Cause Exception -----"); 109 m_nestedException.printStackTrace(s); 110 } 111 } 112 113 120 public void printStackTrace(PrintWriter s) { 121 super.printStackTrace(s); 122 if (m_nestedException != null) { 123 s.println("----- Cause Exception -----"); 124 m_nestedException.printStackTrace(s); 125 } 126 } 127 128 164 public void printStackTrace() { 165 super.printStackTrace(); 166 if (m_nestedException != null) { 167 System.err.println("----- Cause Exception -----"); 168 m_nestedException.printStackTrace(); 169 } 170 } 171 172 } 173 | Popular Tags |