001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.util.struct.parser;
006
007/** Exception for parsing errors. */
008public class ParseException extends Exception {
009  /** The parser position. */
010  private final int m_pos;
011
012  /**
013   * Constructs a ParseException.
014   *
015   * @param pos The parser position.
016   * @param s Reason for parse failure.
017   */
018  public ParseException(int pos, String s) {
019    super(s);
020    m_pos = pos;
021  }
022
023  /**
024   * Constructs a ParseException.
025   *
026   * @param pos The parser position.
027   * @param message Reason for parse failure.
028   * @param cause Exception that caused the parser failure.
029   */
030  public ParseException(int pos, String message, Throwable cause) {
031    super(message, cause);
032    m_pos = pos;
033  }
034
035  /**
036   * Constructs a ParseException.
037   *
038   * @param pos The parser position.
039   * @param cause Exception that caused the parser failure.
040   */
041  public ParseException(int pos, Throwable cause) {
042    super(cause);
043    m_pos = pos;
044  }
045
046  /**
047   * Returns position in parsed string.
048   *
049   * @return Position in parsed string.
050   */
051  public int getPosition() {
052    return m_pos;
053  }
054
055  @Override
056  public String toString() {
057    return m_pos + ": " + getMessage();
058  }
059}