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;
006
007/** Exception thrown when encountering a bad schema. */
008public class BadSchemaException extends Exception {
009  /** The bad schema field. */
010  private final String m_field;
011
012  /**
013   * Constructs a BadSchemaException.
014   *
015   * @param message the detail message.
016   */
017  public BadSchemaException(String message) {
018    super(message);
019    m_field = "";
020  }
021
022  /**
023   * Constructs a BadSchemaException.
024   *
025   * @param message the detail message.
026   * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method).
027   */
028  public BadSchemaException(String message, Throwable cause) {
029    super(message, cause);
030    m_field = "";
031  }
032
033  /**
034   * Constructs a BadSchemaException.
035   *
036   * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method).
037   */
038  public BadSchemaException(Throwable cause) {
039    super(cause);
040    m_field = "";
041  }
042
043  /**
044   * Constructs a BadSchemaException.
045   *
046   * @param field The bad schema field.
047   * @param message the detail message.
048   */
049  public BadSchemaException(String field, String message) {
050    super(message);
051    m_field = field;
052  }
053
054  /**
055   * Constructs a BadSchemaException.
056   *
057   * @param field The bad schema field.
058   * @param message the detail message.
059   * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method).
060   */
061  public BadSchemaException(String field, String message, Throwable cause) {
062    super(message, cause);
063    m_field = field;
064  }
065
066  /**
067   * Gets the name of the bad schema field.
068   *
069   * @return The name of the bad schema field, or an empty string if not applicable.
070   */
071  public String getField() {
072    return m_field;
073  }
074
075  @Override
076  public String toString() {
077    return m_field.isEmpty() ? getMessage() : "field " + m_field + ": " + getMessage();
078  }
079}