Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/ghettojedi/common/ExceptionAdapter.java


1   package com.ghettojedi.common;
2   
3   import java.io.PrintWriter;
4   import java.io.StringWriter;
5   
6   /**
7    * This class is modified from an original by Bruce Eckel.
8    */
9   public class ExceptionAdapter extends RuntimeException {
10      private final String stackTrace;
11      public Exception originalException;
12  
13      private static String unnestToString(Exception e) {
14          if (e instanceof ExceptionAdapter) {
15              return unnestToString(((ExceptionAdapter) e).originalException);
16          }
17          return e.toString();
18      }
19  
20      public ExceptionAdapter(Exception e) {
21          super(unnestToString(e));
22          if (e instanceof ExceptionAdapter) {
23              ExceptionAdapter ea = (ExceptionAdapter) e;
24              this.originalException = ea.originalException;
25              this.stackTrace = ea.stackTrace;
26          } else {
27              this.originalException = e;
28              StringWriter sw = new StringWriter();
29              e.printStackTrace(new PrintWriter(sw));
30              this.stackTrace = sw.toString();
31          }
32      }
33  
34      public void printStackTrace() {
35          printStackTrace(System.err);
36      }
37  
38      public void printStackTrace(java.io.PrintStream s) {
39          synchronized (s) {
40              s.print(getClass().getName() + ": ");
41              s.print(stackTrace);
42          }
43      }
44  
45      public void printStackTrace(java.io.PrintWriter s) {
46          synchronized (s) {
47              s.print(getClass().getName() + ": ");
48              s.print(stackTrace);
49          }
50      }
51  
52      public void rethrow() throws Exception {
53          throw originalException;
54      }
55  }