From 57f386402fe50fd195c3469fc008727f1b66980c Mon Sep 17 00:00:00 2001 From: chiba Date: Fri, 26 Aug 2005 06:48:26 +0000 Subject: [PATCH] improved the compatibility with respect to chained exceptions. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@199 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../javassist/CannotCompileException.java | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main/javassist/CannotCompileException.java b/src/main/javassist/CannotCompileException.java index 6151a0f2..a16a4e5e 100644 --- a/src/main/javassist/CannotCompileException.java +++ b/src/main/javassist/CannotCompileException.java @@ -21,9 +21,30 @@ import javassist.compiler.CompileError; * Thrown when bytecode transformation has failed. */ public class CannotCompileException extends Exception { + private Throwable myCause; + + /** + * Gets the cause of this throwable. + * It is for JDK 1.3 compatibility. + */ + public Throwable getCause() { + return (myCause == this ? null : myCause); + } + + /** + * Initializes the cause of this throwable. + * It is for JDK 1.3 compatibility. + */ + public synchronized Throwable initCause(Throwable cause) { + myCause = cause; + return this; + } + private String message; - private Throwable cause; + /** + * Gets a long message if it is available. + */ public String getReason() { if (message != null) return message; @@ -39,7 +60,7 @@ public class CannotCompileException extends Exception { public CannotCompileException(String msg) { super(msg); message = msg; - cause = null; + initCause(null); } /** @@ -51,7 +72,7 @@ public class CannotCompileException extends Exception { public CannotCompileException(Throwable e) { super("by " + e.toString()); message = null; - cause = e; + initCause(e); } /** @@ -63,7 +84,7 @@ public class CannotCompileException extends Exception { */ public CannotCompileException(String msg, Throwable e) { this(msg); - cause = e; + initCause(e); } /** @@ -95,26 +116,4 @@ public class CannotCompileException extends Exception { public CannotCompileException(ClassFormatError e, String name) { this("invalid class format: " + name, e); } - - /** - * Prints this exception and its backtrace. - */ - public void printStackTrace(java.io.PrintWriter w) { - super.printStackTrace(w); - if (cause != null) { - w.println("Caused by:"); - cause.printStackTrace(w); - } - } - - /** - * Prints this exception and its backtrace. - */ - public void printStackTrace(java.io.PrintStream w) { - super.printStackTrace(w); - if (cause != null) { - w.println("Caused by:"); - cause.printStackTrace(w); - } - } } -- 2.39.5