KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > util > ChainedRuntimeException


1 package xpetstore.util;
2
3
4 /**
5  * Use this class to support chained exceptions in jdk1.3
6  *
7  * @author Isabelle Therrien
8  */

9 public class ChainedRuntimeException
10     extends RuntimeException JavaDoc
11 {
12     //~ Instance fields --------------------------------------------------------
13

14     private Throwable JavaDoc cause = null;
15
16     //~ Constructors -----------------------------------------------------------
17

18     public ChainedRuntimeException( )
19     {
20         super( );
21     }
22
23     public ChainedRuntimeException( String JavaDoc message )
24     {
25         super( message );
26     }
27
28     public ChainedRuntimeException( String JavaDoc message,
29                                     Throwable JavaDoc cause )
30     {
31         super( message );
32         this.cause = cause;
33     }
34
35     public ChainedRuntimeException( Throwable JavaDoc cause )
36     {
37         super( "no message" );
38         this.cause = cause;
39     }
40
41     //~ Methods ----------------------------------------------------------------
42

43     public Throwable JavaDoc getCause( )
44     {
45         return cause;
46     }
47
48     public String JavaDoc 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 JavaDoc 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 JavaDoc 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