You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BCException.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.PrintStream;
  14. import java.io.PrintWriter;
  15. import org.aspectj.bridge.context.CompilationAndWeavingContext;
  16. /**
  17. * Exception to use inside the bcweaver.
  18. */
  19. @SuppressWarnings("serial")
  20. public class BCException extends RuntimeException {
  21. Throwable thrown;
  22. public BCException() {
  23. super();
  24. }
  25. public BCException(String s) {
  26. super(s + "\n" + CompilationAndWeavingContext.getCurrentContext());
  27. }
  28. public BCException(String s, Throwable thrown) {
  29. this(s);
  30. this.thrown = thrown;
  31. }
  32. // TODO: Is it really necessary to re-invent stack trace printing here? Can these methods simply go away?
  33. // The only doubtful "benefit" is that the causing exception's stack trace is printed fully instead of shortened.
  34. // But OTOH, the JVM just omits the lines which were present in the original stack trace above already, so there is
  35. // really no extra information here.
  36. public void printStackTrace() {
  37. printStackTrace(System.err);
  38. }
  39. public void printStackTrace(PrintStream s) {
  40. printStackTrace(new PrintWriter(s));
  41. }
  42. public void printStackTrace(PrintWriter s) {
  43. super.printStackTrace(s);
  44. if (null != thrown) {
  45. s.print("Caused by: ");
  46. thrown.printStackTrace(s);
  47. }
  48. // Flush PrintWriter in case the JVM exits before the stack trace was printed. Otherwise, when e.g. calling
  49. // UnresolvedType.signatureToName from a main method or a test directly and a BCException is thrown, nothing but
  50. // Exception in thread "main"
  51. // would be printed without flushing the PrintWriter, because the JVM exits immediately.
  52. s.flush();
  53. }
  54. }