java.lang.NumberFormatException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(139)

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

NumberFormatException.getMessage介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

static int readInt(BufferedSource source) throws IOException {
 try {
  long result = source.readDecimalLong();
  String line = source.readUtf8LineStrict();
  if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
   throw new IOException("expected an int but was \"" + result + line + "\"");
  }
  return (int) result;
 } catch (NumberFormatException e) {
  throw new IOException(e.getMessage());
 }
}

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

private <T extends Number> T assertConvertible( Supplier<T> func )
{
  try
  {
    return func.get();
  }
  catch ( NumberFormatException e )
  {
    throw new InvalidValuesArgumentException( e.getMessage(), e );
  }
}

代码示例来源:origin: alibaba/fescar

private static Integer getClientPortFromChannel(Channel channel) {
  String address = getAddressFromChannel(channel);
  Integer port = 0;
  try {
    if (address.contains(Constants.IP_PORT_SPLIT_CHAR)) {
      port = Integer.parseInt(address.substring(address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR) + 1));
    }
  } catch (NumberFormatException exx) {
    LOGGER.error(exx.getMessage());
  }
  return port;
}

代码示例来源:origin: alibaba/fescar

private static Integer getClientPortFromChannel(Channel channel) {
  String address = getAddressFromChannel(channel);
  Integer port = 0;
  try {
    if (address.contains(Constants.IP_PORT_SPLIT_CHAR)) {
      port = Integer.parseInt(address.substring(address.lastIndexOf(Constants.IP_PORT_SPLIT_CHAR) + 1));
    }
  } catch (NumberFormatException exx) {
    LOGGER.error(exx.getMessage());
  }
  return port;
}

代码示例来源:origin: prestodb/presto

static int readInt(BufferedSource source) throws IOException {
 try {
  long result = source.readDecimalLong();
  String line = source.readUtf8LineStrict();
  if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
   throw new IOException("expected an int but was \"" + result + line + "\"");
  }
  return (int) result;
 } catch (NumberFormatException e) {
  throw new IOException(e.getMessage());
 }
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as {@code int}.
 * @return the value as {@code int}. If the property does not have value nor default value, then {@code empty} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable integer
 */
default Optional<Integer> getInt(String key) {
 try {
  return get(key).map(String::trim).map(Integer::parseInt);
 } catch (NumberFormatException e) {
  throw new IllegalStateException(String.format("The property '%s' is not an int value: %s", key, e.getMessage()));
 }
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as {@code long}.
 * @return the value as {@code long}. If the property does not have value nor default value, then {@code empty} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable {@code long}
 */
default Optional<Long> getLong(String key) {
 try {
  return get(key).map(String::trim).map(Long::parseLong);
 } catch (NumberFormatException e) {
  throw new IllegalStateException(String.format("The property '%s' is not an long value: %s", key, e.getMessage()));
 }
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as {@code Float}.
 * @return the value as {@code Float}. If the property does not have value nor default value, then {@code empty} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable number
 */
default Optional<Float> getFloat(String key) {
 try {
  return get(key).map(String::trim).map(Float::valueOf);
 } catch (NumberFormatException e) {
  throw new IllegalStateException(String.format("The property '%s' is not an float value: %s", key, e.getMessage()));
 }
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Effective value as {@code Double}.
 * @return the value as {@code Double}. If the property does not have value nor default value, then {@code empty} is returned.
 * @throws NumberFormatException if value is not empty and is not a parsable number
 */
default Optional<Double> getDouble(String key) {
 try {
  return get(key).map(String::trim).map(Double::valueOf);
 } catch (NumberFormatException e) {
  throw new IllegalStateException(String.format("The property '%s' is not an double value: %s", key, e.getMessage()));
 }
}

代码示例来源:origin: apache/kafka

private int allowableClockSkewMs() {
  String allowableClockSkewMsValue = option(ALLOWABLE_CLOCK_SKEW_MILLIS_OPTION);
  int allowableClockSkewMs = 0;
  try {
    allowableClockSkewMs = allowableClockSkewMsValue == null || allowableClockSkewMsValue.trim().isEmpty() ? 0
        : Integer.parseInt(allowableClockSkewMsValue.trim());
  } catch (NumberFormatException e) {
    throw new OAuthBearerConfigException(e.getMessage(), e);
  }
  if (allowableClockSkewMs < 0) {
    throw new OAuthBearerConfigException(
        String.format("Allowable clock skew millis must not be negative: %s", allowableClockSkewMsValue));
  }
  return allowableClockSkewMs;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

static int readInt(BufferedSource source) throws IOException {
 try {
  long result = source.readDecimalLong();
  String line = source.readUtf8LineStrict();
  if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
   throw new IOException("expected an int but was \"" + result + line + "\"");
  }
  return (int) result;
 } catch (NumberFormatException e) {
  throw new IOException(e.getMessage());
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public String getConnectionTestReport( DatabaseMeta databaseMeta ) {
 try {
  OpenERPHelper helper = new OpenERPHelper( databaseMeta );
  helper.StartSession();
  return "Successfully connected to [" + databaseMeta.environmentSubstitute( databaseMeta.getName() ) + "]";
 } catch ( NumberFormatException e ) {
  return "Invalid port number: " + e.getMessage();
 } catch ( Exception e ) {
  return "Connection failed: " + e.getMessage();
 }
}

代码示例来源:origin: square/okhttp

private void readChunkSize() throws IOException {
 // Read the suffix of the previous chunk.
 if (bytesRemainingInChunk != NO_CHUNK_YET) {
  source.readUtf8LineStrict();
 }
 try {
  bytesRemainingInChunk = source.readHexadecimalUnsignedLong();
  String extensions = source.readUtf8LineStrict().trim();
  if (bytesRemainingInChunk < 0 || (!extensions.isEmpty() && !extensions.startsWith(";"))) {
   throw new ProtocolException("expected chunk size and optional extensions but was \""
     + bytesRemainingInChunk + extensions + "\"");
  }
 } catch (NumberFormatException e) {
  throw new ProtocolException(e.getMessage());
 }
 if (bytesRemainingInChunk == 0L) {
  hasMoreChunks = false;
  trailers = readHeaders();
  HttpHeaders.receiveHeaders(client.cookieJar(), url, trailers);
  endOfInput(true, null);
 }
}

代码示例来源:origin: alibaba/fastjson

public final Number decimalValue(boolean decimal) {
  char chLocal = charAt(np + sp - 1);
  try {
    if (chLocal == 'F') {
      return Float.parseFloat(numberString());
    }
    if (chLocal == 'D') {
      return Double.parseDouble(numberString());
    }
    if (decimal) {
      return decimalValue();
    } else {
      return doubleValue();
    }
  } catch (NumberFormatException ex) {
    throw new JSONException(ex.getMessage() + ", " + info());
  }
}

代码示例来源:origin: square/okio

@Test public void longDecimalStringTooLowThrows() throws IOException {
 try {
  sink.writeUtf8("-9223372036854775809"); // Right size but cannot fit.
  sink.emit();
  source.readDecimalLong();
  fail();
 } catch (NumberFormatException e) {
  assertEquals("Number too large: -9223372036854775809", e.getMessage());
 }
}

代码示例来源:origin: square/okio

@Test public void longHexStringTooLongThrows() throws IOException {
 try {
  sink.writeUtf8("fffffffffffffffff");
  sink.emit();
  source.readHexadecimalUnsignedLong();
  fail();
 } catch (NumberFormatException e) {
  assertEquals("Number too large: fffffffffffffffff", e.getMessage());
 }
}

代码示例来源:origin: square/okio

@Test public void longDecimalStringTooLongThrows() throws IOException {
 try {
  sink.writeUtf8("12345678901234567890"); // Too many digits.
  sink.emit();
  source.readDecimalLong();
  fail();
 } catch (NumberFormatException e) {
  assertEquals("Number too large: 12345678901234567890", e.getMessage());
 }
}

代码示例来源:origin: square/okio

@Test public void longDecimalStringTooShortThrows() throws IOException {
 try {
  sink.writeUtf8(" ");
  sink.emit();
  source.readDecimalLong();
  fail();
 } catch (NumberFormatException e) {
  assertEquals("Expected leading [0-9] or '-' character but was 0x20", e.getMessage());
 }
}

代码示例来源:origin: square/okio

@Test public void longHexStringTooShortThrows() throws IOException {
 try {
  sink.writeUtf8(" ");
  sink.emit();
  source.readHexadecimalUnsignedLong();
  fail();
 } catch (NumberFormatException e) {
  assertEquals("Expected leading [0-9a-fA-F] character but was 0x20", e.getMessage());
 }
}

代码示例来源:origin: square/okio

@Test public void longDecimalStringTooHighThrows() throws IOException {
 try {
  sink.writeUtf8("9223372036854775808"); // Right size but cannot fit.
  sink.emit();
  source.readDecimalLong();
  fail();
 } catch (NumberFormatException e) {
  assertEquals("Number too large: 9223372036854775808", e.getMessage());
 }
}

相关文章