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