java.util.InputMismatchException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中java.util.InputMismatchException.<init>()方法的一些代码示例,展示了InputMismatchException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InputMismatchException.<init>()方法的具体详情如下:
包路径:java.util.InputMismatchException
类名称:InputMismatchException
方法名:<init>

InputMismatchException.<init>介绍

[英]Constructs a new InputMismatchException with the current stack trace filled in.
[中]构造一个新的InputMismatchException,并填充当前堆栈跟踪。

代码示例

代码示例来源:origin: cmusphinx/sphinx4

public void assertToken(String expected, String actual) {
    if (actual.equals(expected))
      return;

    String msg;
    msg = String.format("'%s' expected, '%s' got", expected, actual);
    throw new InputMismatchException(msg);
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as a long integer, and returns the long integer.
 *
 * @return the next long integer on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code long}
 */
public static long readLong() {
  try {
    return scanner.nextLong();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'long' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'long' value from standard input, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as a double, and returns the double.
 *
 * @return the next double on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code double}
 */
public static double readDouble() {
  try {
    return scanner.nextDouble();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'double' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'double' value from standard input, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as a float, and returns the float.
 *
 * @return the next float on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code float}
 */
public static float readFloat() {
  try {
    return scanner.nextFloat();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'float' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'float' value from standard input, "
                    + "but there no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as an integer, and returns the integer.
 *
 * @return the next integer on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as an {@code int}
 */
public static int readInt() {
  try {
    return scanner.nextInt();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read an 'int' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read an 'int' value from standard input, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as a short integer, and returns the short integer.
 *
 * @return the next short integer on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code short}
 */
public static short readShort() {
  try {
    return scanner.nextShort();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'short' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'short' value from standard input, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as a byte, and returns the byte.
 *
 * @return the next byte on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code byte}
 */
public static byte readByte() {
  try {
    return scanner.nextByte();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'byte' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'byte' value from standard input, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code long},
 * and returns the {@code long}.
 *
 * @return the next {@code long} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code long}
 */
public long readLong() {
  try {
    return scanner.nextLong();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'long' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read a 'long' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code double},
 * and returns the {@code double}.
 *
 * @return the next {@code double} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code double}
 */
public double readDouble() {
  try {
    return scanner.nextDouble();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'double' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read a 'double' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code short},
 * and returns the {@code short}.
 *
 * @return the next {@code short} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code short}
 */
public short readShort() {
  try {
    return scanner.nextShort();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'short' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read a 'short' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code int},
 * and returns the {@code int}.
 *
 * @return the next {@code int} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as an {@code int}
 */
public int readInt() {
  try {
    return scanner.nextInt();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read an 'int' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read an 'int' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code float},
 * and returns the {@code float}.
 *
 * @return the next {@code float} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code float}
 */
public float readFloat() {
  try {
    return scanner.nextFloat();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'float' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read a 'float' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code byte},
 * and returns the {@code byte}.
 * <p>
 * To read binary data, use {@link BinaryIn}.
 *
 * @return the next {@code byte} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code byte}
 */
public byte readByte() {
  try {
    return scanner.nextByte();
  }
  catch (InputMismatchException e) {
    String token = scanner.next();
    throw new InputMismatchException("attempts to read a 'byte' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attemps to read a 'byte' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from this input stream, parses it as a {@code boolean}
 * (interpreting either {@code "true"} or {@code "1"} as {@code true},
 * and either {@code "false"} or {@code "0"} as {@code false}).
 *
 * @return the next {@code boolean} in this input stream
 * @throws NoSuchElementException if the input stream is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code boolean}
 */
public boolean readBoolean() {
  try {
    String token = readString();
    if ("true".equalsIgnoreCase(token))  return true;
    if ("false".equalsIgnoreCase(token)) return false;
    if ("1".equals(token))               return true;
    if ("0".equals(token))               return false;
    throw new InputMismatchException("attempts to read a 'boolean' value from the input stream, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'boolean' value from the input stream, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Reads the next token from standard input, parses it as a boolean,
 * and returns the boolean.
 *
 * @return the next boolean on standard input
 * @throws NoSuchElementException if standard input is empty
 * @throws InputMismatchException if the next token cannot be parsed as a {@code boolean}:
 *    {@code true} or {@code 1} for true, and {@code false} or {@code 0} for false,
 *    ignoring case
 */
public static boolean readBoolean() {
  try {
    String token = readString();
    if ("true".equalsIgnoreCase(token))  return true;
    if ("false".equalsIgnoreCase(token)) return false;
    if ("1".equals(token))               return true;
    if ("0".equals(token))               return false;
    throw new InputMismatchException("attempts to read a 'boolean' value from standard input, "
                    + "but the next token is \"" + token + "\"");
  }
  catch (NoSuchElementException e) {
    throw new NoSuchElementException("attempts to read a 'boolean' value from standard input, "
                    + "but no more tokens are available");
  }
}

代码示例来源:origin: cmusphinx/sphinx4

private EventMap parseEventMap(KaldiTextParser parser) {
  String token = parser.getToken();
  if ("CE".equals(token))
    return new ConstantEventMap(parser.getInt());
  if ("SE".equals(token))
    return parseSplitEventMap(parser);
  if ("TE".equals(token))
    return parseTableEventMap(parser);
  if ("NULL".equals(token))
    return null;
  throw new InputMismatchException(token);
}

代码示例来源:origin: robovm/robovm

matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();

代码示例来源:origin: robovm/robovm

matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();

代码示例来源:origin: robovm/robovm

matchSuccessful = false;
recoverPreviousStatus();
throw new InputMismatchException();

代码示例来源:origin: robovm/robovm

if (!matcher.matches()) {
  recoverPreviousStatus();
  throw new InputMismatchException();

相关文章

InputMismatchException类方法