選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FOPException.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  3. * For details on use and redistribution please refer to the
  4. * LICENSE file included with these sources."
  5. */
  6. package org.apache.fop.apps;
  7. import org.xml.sax.SAXException;
  8. /**
  9. * Exception thrown when FOP has a problem
  10. */
  11. public class FOPException extends Exception {
  12. private static final String EXCEPTION_SEPARATOR = "\n---------\n";
  13. private Throwable _exception;
  14. /**
  15. * create a new FOP Exception
  16. *
  17. * @param message descriptive message
  18. */
  19. public FOPException(String message) {
  20. super(message);
  21. }
  22. public FOPException(Throwable e) {
  23. super(e.getMessage());
  24. setException(e);
  25. }
  26. public FOPException(String message, Throwable e) {
  27. super(message);
  28. setException(e);
  29. }
  30. protected void setException(Throwable t)
  31. {
  32. _exception = t;
  33. }
  34. public Throwable getException()
  35. {
  36. return _exception;
  37. }
  38. protected Throwable getRootException()
  39. {
  40. Throwable result = _exception;
  41. if (result instanceof SAXException) {
  42. result = ((SAXException)result).getException();
  43. }
  44. if (result instanceof java.lang.reflect.InvocationTargetException) {
  45. result = ((java.lang.reflect.InvocationTargetException)result).getTargetException();
  46. }
  47. if (result != _exception) {
  48. return result;
  49. }
  50. return null;
  51. }
  52. public void printStackTrace()
  53. {
  54. synchronized (System.err) {
  55. super.printStackTrace();
  56. if (_exception != null) {
  57. System.err.println(EXCEPTION_SEPARATOR);
  58. _exception.printStackTrace();
  59. }
  60. if (getRootException() != null) {
  61. System.err.println(EXCEPTION_SEPARATOR);
  62. getRootException().printStackTrace();
  63. }
  64. }
  65. }
  66. public void printStackTrace(java.io.PrintStream stream)
  67. {
  68. synchronized (stream) {
  69. super.printStackTrace(stream);
  70. if (_exception != null) {
  71. stream.println(EXCEPTION_SEPARATOR);
  72. _exception.printStackTrace(stream);
  73. }
  74. if (getRootException() != null) {
  75. System.err.println(EXCEPTION_SEPARATOR);
  76. getRootException().printStackTrace(stream);
  77. }
  78. }
  79. }
  80. public void printStackTrace(java.io.PrintWriter writer)
  81. {
  82. synchronized (writer) {
  83. super.printStackTrace(writer);
  84. if (_exception != null) {
  85. writer.println(EXCEPTION_SEPARATOR);
  86. _exception.printStackTrace(writer);
  87. }
  88. if (getRootException() != null) {
  89. System.err.println(EXCEPTION_SEPARATOR);
  90. getRootException().printStackTrace(writer);
  91. }
  92. }
  93. }
  94. }