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

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