diff options
Diffstat (limited to 'src/org/apache/fop/apps/FOPException.java')
-rw-r--r-- | src/org/apache/fop/apps/FOPException.java | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/src/org/apache/fop/apps/FOPException.java b/src/org/apache/fop/apps/FOPException.java index 94ca52bdf..765d9eede 100644 --- a/src/org/apache/fop/apps/FOPException.java +++ b/src/org/apache/fop/apps/FOPException.java @@ -6,11 +6,16 @@ package org.apache.fop.apps; +import org.xml.sax.SAXException; + + /** * Exception thrown when FOP has a problem */ public class FOPException extends Exception { + private static final String EXCEPTION_SEPARATOR = "\n---------\n"; + private Throwable _exception; /** @@ -23,11 +28,84 @@ public class FOPException extends Exception { } public FOPException(Throwable e) { super(e.getMessage()); - _exception = e; + setException(e); + } + + public FOPException(String message, Throwable e) { + super(message); + setException(e); + } + + protected void setException(Throwable t) + { + _exception = t; } public Throwable getException() { return _exception; } + + protected Throwable getRootException() + { + Throwable result = _exception; + + if (result instanceof SAXException) { + result = ((SAXException)result).getException(); + } + if (result instanceof java.lang.reflect.InvocationTargetException) { + result = ((java.lang.reflect.InvocationTargetException)result).getTargetException(); + } + if (result != _exception) { + return result; + } + return null; + } + + + public void printStackTrace() + { + synchronized (System.err) { + super.printStackTrace(); + if (_exception != null) { + System.err.println(EXCEPTION_SEPARATOR); + _exception.printStackTrace(); + } + if (getRootException() != null) { + System.err.println(EXCEPTION_SEPARATOR); + getRootException().printStackTrace(); + } + } + } + + public void printStackTrace(java.io.PrintStream stream) + { + synchronized (stream) { + super.printStackTrace(stream); + if (_exception != null) { + stream.println(EXCEPTION_SEPARATOR); + _exception.printStackTrace(stream); + } + if (getRootException() != null) { + System.err.println(EXCEPTION_SEPARATOR); + getRootException().printStackTrace(stream); + } + } + } + + public void printStackTrace(java.io.PrintWriter writer) + { + synchronized (writer) { + super.printStackTrace(writer); + if (_exception != null) { + writer.println(EXCEPTION_SEPARATOR); + _exception.printStackTrace(writer); + } + if (getRootException() != null) { + System.err.println(EXCEPTION_SEPARATOR); + getRootException().printStackTrace(writer); + } + } + } + } |