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

BuildException.java 5.6 kB

8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant;
  19. /**
  20. * Signals an error condition during a build
  21. */
  22. public class BuildException extends RuntimeException {
  23. private static final long serialVersionUID = -5419014565354664240L;
  24. /** Location in the build file where the exception occurred */
  25. private Location location = Location.UNKNOWN_LOCATION;
  26. /**
  27. * Constructs a build exception with no descriptive information.
  28. */
  29. public BuildException() {
  30. super();
  31. }
  32. /**
  33. * Constructs an exception with the given descriptive message.
  34. *
  35. * @param message A description of or information about the exception.
  36. * Should not be {@code null}.
  37. */
  38. public BuildException(String message) {
  39. super(message);
  40. }
  41. /**
  42. * Constructs an exception with the given format pattern and arguments.
  43. *
  44. * @param pattern A description of or information about the exception.
  45. * Should not be {@code null}.
  46. * @param formatArguments
  47. * @see String#format(String, Object...)
  48. * @since Ant 1.11
  49. */
  50. public BuildException(String pattern, Object... formatArguments) {
  51. super(String.format(pattern, formatArguments));
  52. }
  53. /**
  54. * Constructs an exception with the given message and exception as
  55. * a root cause.
  56. *
  57. * @param message A description of or information about the exception.
  58. * Should not be <code>null</code> unless a cause is specified.
  59. * @param cause The exception that might have caused this one.
  60. * May be <code>null</code>.
  61. */
  62. public BuildException(String message, Throwable cause) {
  63. super(message, cause);
  64. }
  65. /**
  66. * Constructs an exception with the given message and exception as
  67. * a root cause and a location in a file.
  68. *
  69. * @param msg A description of or information about the exception.
  70. * Should not be <code>null</code> unless a cause is specified.
  71. * @param cause The exception that might have caused this one.
  72. * May be <code>null</code>.
  73. * @param location The location in the project file where the error
  74. * occurred. Must not be <code>null</code>.
  75. */
  76. public BuildException(String msg, Throwable cause, Location location) {
  77. this(msg, cause);
  78. this.location = location;
  79. }
  80. /**
  81. * Constructs an exception with the given exception as a root cause.
  82. *
  83. * @param cause The exception that might have caused this one.
  84. * Should not be <code>null</code>.
  85. */
  86. public BuildException(Throwable cause) {
  87. super(cause);
  88. }
  89. /**
  90. * Constructs an exception with the given descriptive message and a
  91. * location in a file.
  92. *
  93. * @param message A description of or information about the exception.
  94. * Should not be <code>null</code>.
  95. * @param location The location in the project file where the error
  96. * occurred. Must not be <code>null</code>.
  97. */
  98. public BuildException(String message, Location location) {
  99. super(message);
  100. this.location = location;
  101. }
  102. /**
  103. * Constructs an exception with the given exception as
  104. * a root cause and a location in a file.
  105. *
  106. * @param cause The exception that might have caused this one.
  107. * Should not be <code>null</code>.
  108. * @param location The location in the project file where the error
  109. * occurred. Must not be <code>null</code>.
  110. */
  111. public BuildException(Throwable cause, Location location) {
  112. this(cause);
  113. this.location = location;
  114. }
  115. /**
  116. * Returns the nested exception, if any.
  117. *
  118. * @return the nested exception, or <code>null</code> if no
  119. * exception is associated with this one
  120. * @deprecated Use {@link #getCause} instead.
  121. */
  122. public Throwable getException() {
  123. return getCause();
  124. }
  125. /**
  126. * Returns the location of the error and the error message.
  127. *
  128. * @return the location of the error and the error message
  129. */
  130. public String toString() {
  131. return location.toString() + getMessage();
  132. }
  133. /**
  134. * Sets the file location where the error occurred.
  135. *
  136. * @param location The file location where the error occurred.
  137. * Must not be <code>null</code>.
  138. */
  139. public void setLocation(Location location) {
  140. this.location = location;
  141. }
  142. /**
  143. * Returns the file location where the error occurred.
  144. *
  145. * @return the file location where the error occurred.
  146. */
  147. public Location getLocation() {
  148. return location;
  149. }
  150. }