123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
- * For details on use and redistribution please refer to the
- * LICENSE file included with these sources."
- */
-
- 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;
-
- /**
- * create a new FOP Exception
- *
- * @param message descriptive message
- */
- public FOPException(String message) {
- super(message);
- }
- public FOPException(Throwable e) {
- super(e.getMessage());
- 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);
- }
- }
- }
-
- }
|