1 package xpetstore.util; 2 3 4 9 public class ChainedRuntimeException 10 extends RuntimeException 11 { 12 14 private Throwable cause = null; 15 16 18 public ChainedRuntimeException( ) 19 { 20 super( ); 21 } 22 23 public ChainedRuntimeException( String message ) 24 { 25 super( message ); 26 } 27 28 public ChainedRuntimeException( String message, 29 Throwable cause ) 30 { 31 super( message ); 32 this.cause = cause; 33 } 34 35 public ChainedRuntimeException( Throwable cause ) 36 { 37 super( "no message" ); 38 this.cause = cause; 39 } 40 41 43 public Throwable getCause( ) 44 { 45 return cause; 46 } 47 48 public String toString( ) 49 { 50 if ( cause == null ) 51 { 52 return super.toString( ); 53 } 54 else 55 { 56 return super.toString( ) + " <---- Caused by: " + cause.toString( ) + " ---->"; 57 } 58 } 59 60 public void printStackTrace( ) 61 { 62 super.printStackTrace( ); 63 64 if ( cause != null ) 65 { 66 System.err.println( "<---- Caused by:" ); 67 cause.printStackTrace( ); 68 System.err.println( "---->" ); 69 } 70 } 71 72 public void printStackTrace( java.io.PrintStream ps ) 73 { 74 super.printStackTrace( ps ); 75 76 if ( cause != null ) 77 { 78 ps.println( "<---- Caused by:" ); 79 cause.printStackTrace( ps ); 80 ps.println( "---->" ); 81 } 82 } 83 84 public void printStackTrace( java.io.PrintWriter pw ) 85 { 86 super.printStackTrace( pw ); 87 88 if ( cause != null ) 89 { 90 pw.println( "<---- Caused by:" ); 91 cause.printStackTrace( pw ); 92 pw.println( "---->" ); 93 } 94 } 95 } 96 | Popular Tags |