001package io.ebean.text;
002
003/**
004 * An exception occurred typically in processing CSV, JSON or XML.
005 */
006public class TextException extends RuntimeException {
007
008  private static final long serialVersionUID = 1601310159486033148L;
009  private String text;
010
011  /**
012   * Construct with an error message.
013   */
014  public TextException(String msg) {
015    super(msg);
016  }
017
018  /**
019   * Construct with a message and cause.
020   */
021  public TextException(String msg, Exception e) {
022    super(msg, e);
023  }
024
025  /**
026   * Construct with a cause.
027   */
028  public TextException(Exception e) {
029    super(e);
030  }
031
032  /**
033   * Constructor for a detailed exception.
034   *
035   * @param message
036   *          the message. The placeholder {} will be replaced by
037   *          <code>text</code>
038   * @param text
039   *          the fault text.
040   * @param cause
041   *          the case
042   */
043  public TextException(String message, String text, Exception cause) {
044    super(message.replace("{}", String.valueOf(text)), cause);
045    this.text = text;
046  }
047
048  /**
049   * Constructor for a detailed exception.
050   *
051   * @param message
052   *          the message. The placeholder {} will be replaced by
053   *          <code>text</code>
054   * @param text
055   *          the fault text.
056   */
057  public TextException(String message, String text) {
058    super(message.replace("{}", String.valueOf(text)));
059    this.text = text;
060  }
061
062  /**
063   * Return the text, that caused the error. (e.g. the JSON). May be null.
064   */
065  public String getText() {
066    return text;
067  }
068}