1 package org.crazybob.util; 2 3 import java.io.*; 4 5 13 public class NestedException extends RuntimeException { 14 15 16 public static RuntimeException wrap(Throwable t) { 17 if (t instanceof RuntimeException ) return (RuntimeException ) t; 18 return new NestedException(t); 19 } 20 21 private String message; 22 private String stackTrace; 23 24 25 private NestedException(Throwable t) { 26 super(); 27 this.message = t.getMessage(); 28 StringWriter out = new StringWriter(); 29 t.printStackTrace(new PrintWriter(out)); 30 this.stackTrace = out.toString(); 31 } 32 33 public String toString() { 34 return this.getMessage(); 35 } 36 37 public String getMessage() { 38 return this.message; 39 } 40 41 public void printStackTrace() { 42 System.err.print(this.stackTrace); 43 } 44 45 public void printStackTrace(PrintStream out) { 46 printStackTrace(new PrintWriter(out)); 47 } 48 49 public void printStackTrace(PrintWriter out) { 50 out.print(this.stackTrace); 51 } 52 53 } 54 | Popular Tags |