1 5 package com.opensymphony.workflow; 6 7 import java.io.PrintStream ; 8 import java.io.PrintWriter ; 9 10 11 16 public class WorkflowException extends Exception { 17 19 private Throwable rootCause; 20 21 23 public WorkflowException() { 24 } 25 26 public WorkflowException(String s) { 27 super(s); 28 } 29 30 public WorkflowException(String s, Throwable rootCause) { 31 super(s); 32 this.rootCause = rootCause; 33 } 34 35 public WorkflowException(Throwable rootCause) { 36 this.rootCause = rootCause; 37 } 38 39 41 public String getMessage() { 42 StringBuffer sb = new StringBuffer (); 43 String msg = super.getMessage(); 44 45 if (msg != null) { 46 sb.append(msg); 47 48 if (rootCause != null) { 49 sb.append(": "); 50 } 51 } 52 53 if (rootCause != null) { 54 sb.append("root cause: " + ((rootCause.getMessage() == null) ? rootCause.toString() : rootCause.getMessage())); 55 } 56 57 return sb.toString(); 58 } 59 60 public Throwable getRootCause() { 61 return rootCause; 62 } 63 64 public void printStackTrace() { 65 super.printStackTrace(); 66 67 if (rootCause != null) { 68 synchronized (System.err) { 69 System.err.println("\nRoot cause:"); 70 rootCause.printStackTrace(); 71 } 72 } 73 } 74 75 public void printStackTrace(PrintStream s) { 76 super.printStackTrace(s); 77 78 if (rootCause != null) { 79 synchronized (s) { 80 s.println("\nRoot cause:"); 81 rootCause.printStackTrace(s); 82 } 83 } 84 } 85 86 public void printStackTrace(PrintWriter s) { 87 super.printStackTrace(s); 88 89 if (rootCause != null) { 90 synchronized (s) { 91 s.println("\nRoot cause:"); 92 rootCause.printStackTrace(s); 93 } 94 } 95 } 96 } 97 | Popular Tags |