1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.mail.internet;
  6. /**
  7. * The exception thrown when a wrongly formatted address is encountered.
  8. *
  9. * @author Bill Shannon
  10. * @author Max Spivak
  11. */
  12. public class AddressException extends ParseException {
  13. /**
  14. * The string being parsed.
  15. *
  16. * @serial
  17. */
  18. protected String ref = null;
  19. /**
  20. * The index in the string where the error occurred, or -1 if not known.
  21. *
  22. * @serial
  23. */
  24. protected int pos = -1;
  25. /**
  26. * Constructs an AddressException with no detail message.
  27. */
  28. public AddressException() {
  29. super();
  30. }
  31. /**
  32. * Constructs an AddressException with the specified detail message.
  33. * @param s the detail message
  34. */
  35. public AddressException(String s) {
  36. super(s);
  37. }
  38. /**
  39. * Constructs an AddressException with the specified detail message
  40. * and reference info.
  41. *
  42. * @param s the detail message
  43. */
  44. public AddressException(String s, String ref) {
  45. super(s);
  46. this.ref = ref;
  47. }
  48. /**
  49. * Constructs an AddressException with the specified detail message
  50. * and reference info.
  51. *
  52. * @param s the detail message
  53. */
  54. public AddressException(String s, String ref, int pos) {
  55. super(s);
  56. this.ref = ref;
  57. this.pos = pos;
  58. }
  59. /**
  60. * Get the string that was being parsed when the error was detected
  61. * (null if not relevant).
  62. */
  63. public String getRef() {
  64. return ref;
  65. }
  66. /**
  67. * Get the position with the reference string where the error was
  68. * detected (-1 if not relevant).
  69. */
  70. public int getPos() {
  71. return pos;
  72. }
  73. public String toString() {
  74. String s = super.toString();
  75. if (ref == null)
  76. return s;
  77. s += " in string ``" + ref + "''";
  78. if (pos < 0)
  79. return s;
  80. return s + " at position " + pos;
  81. }
  82. }