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.

CannotCompileException.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later.
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. */
  15. package javassist;
  16. import javassist.compiler.CompileError;
  17. /**
  18. * Thrown when bytecode transformation has failed.
  19. */
  20. public class CannotCompileException extends Exception {
  21. private Throwable myCause;
  22. /**
  23. * Gets the cause of this throwable.
  24. * It is for JDK 1.3 compatibility.
  25. */
  26. public Throwable getCause() {
  27. return (myCause == this ? null : myCause);
  28. }
  29. /**
  30. * Initializes the cause of this throwable.
  31. * It is for JDK 1.3 compatibility.
  32. */
  33. public synchronized Throwable initCause(Throwable cause) {
  34. myCause = cause;
  35. return this;
  36. }
  37. private String message;
  38. /**
  39. * Gets a long message if it is available.
  40. */
  41. public String getReason() {
  42. if (message != null)
  43. return message;
  44. else
  45. return this.toString();
  46. }
  47. /**
  48. * Constructs a CannotCompileException with a message.
  49. *
  50. * @param msg the message.
  51. */
  52. public CannotCompileException(String msg) {
  53. super(msg);
  54. message = msg;
  55. initCause(null);
  56. }
  57. /**
  58. * Constructs a CannotCompileException with an <code>Exception</code>
  59. * representing the cause.
  60. *
  61. * @param e the cause.
  62. */
  63. public CannotCompileException(Throwable e) {
  64. super("by " + e.toString());
  65. message = null;
  66. initCause(e);
  67. }
  68. /**
  69. * Constructs a CannotCompileException with a detailed message
  70. * and an <code>Exception</code> representing the cause.
  71. *
  72. * @param msg the message.
  73. * @param e the cause.
  74. */
  75. public CannotCompileException(String msg, Throwable e) {
  76. this(msg);
  77. initCause(e);
  78. }
  79. /**
  80. * Constructs a CannotCompileException with a
  81. * <code>NotFoundException</code>.
  82. */
  83. public CannotCompileException(NotFoundException e) {
  84. this("cannot find " + e.getMessage(), e);
  85. }
  86. /**
  87. * Constructs a CannotCompileException with an <code>CompileError</code>.
  88. */
  89. public CannotCompileException(CompileError e) {
  90. this("[source error] " + e.getMessage(), e);
  91. }
  92. /**
  93. * Constructs a CannotCompileException
  94. * with a <code>ClassNotFoundException</code>.
  95. */
  96. public CannotCompileException(ClassNotFoundException e, String name) {
  97. this("cannot find " + name, e);
  98. }
  99. /**
  100. * Constructs a CannotCompileException with a ClassFormatError.
  101. */
  102. public CannotCompileException(ClassFormatError e, String name) {
  103. this("invalid class format: " + name, e);
  104. }
  105. }