KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dynaop > util > NestedException


1 package dynaop.util;
2
3 import java.io.*;
4
5 /**
6  * Turns a nested exception into a runtime exception.
7  *
8  * @author Bob Lee (crazybob@crazybob.org)
9  */

10 public class NestedException extends RuntimeException JavaDoc {
11
12     /** Wrap another exeception in a RuntimeException. */
13     public static RuntimeException JavaDoc wrap(Throwable JavaDoc t) {
14         if (t instanceof RuntimeException JavaDoc) return (RuntimeException JavaDoc) t;
15         return new NestedException(t);
16     }
17
18     Throwable JavaDoc throwable;
19
20     /** Wraps another exeception. */
21     NestedException(Throwable JavaDoc t) {
22         super();
23         this.throwable = t;
24     }
25
26     public String JavaDoc toString() {
27         return this.getMessage();
28     }
29
30     public String JavaDoc getMessage() {
31         return this.throwable.getMessage();
32     }
33
34     public void printStackTrace() {
35         this.throwable.printStackTrace();
36     }
37
38     public void printStackTrace(PrintStream out) {
39         this.throwable.printStackTrace(out);
40     }
41
42     public void printStackTrace(PrintWriter out) {
43         this.throwable.printStackTrace(out);
44     }
45
46     public Throwable JavaDoc getNested() {
47         return throwable;
48     }
49 }
50
Popular Tags