ParseException.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2004-2008 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.expression;
  17. /**
  18. * Base class for exceptions occurring during expression parsing and evaluation.
  19. *
  20. * @author Andy Clement
  21. */
  22. public class ParseException extends Exception {
  23. /**
  24. * The expression string.
  25. */
  26. private String expressionString;
  27. /**
  28. * Creates a new expression exception. The expressionString field should be set by a later call to
  29. * setExpressionString().
  30. *
  31. * @param cause the underlying cause of this exception
  32. */
  33. public ParseException(Throwable cause) {
  34. super(cause);
  35. }
  36. /**
  37. * Creates a new expression parsing exception.
  38. *
  39. * @param expressionString the expression string that could not be parsed
  40. * @param cause the underlying cause of this exception
  41. */
  42. public ParseException(String expressionString, Throwable cause) {
  43. this(expressionString, "Exception occurred whilst handling '" + expressionString + "'", cause);
  44. }
  45. /**
  46. * Creates a new expression exception.
  47. *
  48. * @param expressionString the expression string
  49. * @param message a descriptive message
  50. * @param cause the underlying cause of this exception
  51. */
  52. public ParseException(String expressionString, String message, Throwable cause) {
  53. super(message, cause);
  54. this.expressionString = expressionString;
  55. }
  56. /**
  57. * Creates a new expression exception.
  58. *
  59. * @param expressionString the expression string
  60. * @param message a descriptive message
  61. */
  62. public ParseException(String expressionString, String message) {
  63. super(message);
  64. this.expressionString = expressionString;
  65. }
  66. /**
  67. * Set the expression string, called on exceptions where the expressionString is not known at the time of exception
  68. * creation.
  69. *
  70. * @param expressionString the expression string
  71. */
  72. protected final void setExpressionString(String expressionString) {
  73. this.expressionString = expressionString;
  74. }
  75. /**
  76. * @return the expression string
  77. */
  78. public final String getExpressionString() {
  79. return expressionString;
  80. }
  81. }