RuntimeFault.java
00001 package edu.virtualschool.jwaa;
00002
00003 import java.io.ByteArrayOutputStream;
00004 import java.io.PrintStream;
00005 import java.io.PrintWriter;
00006
00013 public class RuntimeFault extends RuntimeException
00014 {
00015 private final Throwable nextInChain;
00016
00017 public RuntimeFault(Object message, Throwable e)
00018 {
00019 super(message.toString());
00020 this.nextInChain = e;
00021 }
00022 public RuntimeFault(String message) { this(message, null); }
00023 public RuntimeFault(Throwable e) { this("", e); }
00024
00025 public final void printStackTrace()
00026 {
00027 printStackTrace(System.err);
00028 }
00029 public final void printStackTrace(PrintStream ps)
00030 {
00031 super.printStackTrace(ps);
00032 if (nextInChain != null)
00033 {
00034 ps.print("chainedTo: ");
00035 nextInChain.printStackTrace(ps);
00036 }
00037 }
00038 public final void printStackTrace(PrintWriter pw)
00039 {
00040 super.printStackTrace(pw);
00041 if (nextInChain != null)
00042 {
00043 pw.print("chainedTo: ");
00044 nextInChain.printStackTrace(pw);
00045 }
00046 }
00047
00048 public final static String getStackTrace(Throwable e)
00049 {
00050 if (e == null) return "";
00051 ByteArrayOutputStream bos = new ByteArrayOutputStream();
00052 PrintWriter pw = new PrintWriter(bos);
00053 e.printStackTrace(pw);
00054 pw.close();
00055 return new String(bos.toByteArray());
00056 }
00057 public final Throwable getChainedException()
00058 {
00059 return nextInChain;
00060 }
00061 public final String getType()
00062 {
00063 String name = getClass().getName();
00064 int lastDot = name.lastIndexOf(".");
00065 return name.substring(lastDot+1);
00066 }
00067 public final String toString()
00068 {
00069 return ""+getMessage()+" ["+getType()+"]";
00070 }
00076 public String getReason() { return ""; }
00081 public String getAdvice() { return ""; }
00082 }