KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > util > UncheckedException


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.util;
4
5 import java.io.PrintWriter JavaDoc;
6 import java.io.PrintStream JavaDoc;
7
8 /**
9  * Unchecked exception and also a wrapper for checked exceptions.
10  */

11 public class UncheckedException extends RuntimeException JavaDoc {
12
13     protected final Throwable JavaDoc cause;
14
15     // ---------------------------------------------------------------- constructors
16

17     public UncheckedException(Throwable JavaDoc t) {
18         super(t.getMessage());
19         cause = t;
20     }
21
22     public UncheckedException() {
23         super();
24         cause = null;
25     }
26
27     public UncheckedException(String JavaDoc message) {
28         super(message);
29         cause = null;
30     }
31
32     public UncheckedException(String JavaDoc message, Throwable JavaDoc t) {
33         super(message, t);
34         cause = t;
35     }
36
37     // ---------------------------------------------------------------- stack trace
38

39     public void printStackTrace() {
40         printStackTrace(System.err);
41     }
42
43     public void printStackTrace(PrintStream JavaDoc printStream) {
44         synchronized (printStream) {
45             printStream.print(getClass().getName() + ": ");
46             super.printStackTrace(printStream);
47         }
48     }
49
50     public void printStackTrace(PrintWriter JavaDoc printWriter) {
51         synchronized (printWriter) {
52             printWriter.print(getClass().getName() + ": ");
53             super.printStackTrace(printWriter);
54         }
55     }
56
57     // ---------------------------------------------------------------- cause
58

59     /**
60      * Rethrows cause.
61      */

62     public void rethrow() throws Throwable JavaDoc {
63         if (cause == null) {
64             return;
65         }
66         throw cause;
67     }
68
69     /**
70      * Returns exception cause.
71      */

72     public Throwable JavaDoc getCause() {
73         return cause;
74     }
75
76 }
77
Popular Tags