java.lang.Error.initCause()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(141)

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

Error.initCause介绍

暂无

代码示例

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

/**
 * Checks the availability of the JAXP classes on the classpath.
 * @throws NoClassDefFoundError if the required JAXP classes are not availabile on the classpath.
 */
static void checkJAXPAvailability() {
  try {
    XmlConfigurator.class.getName();
  }
  catch (NoClassDefFoundError error) {
    Error tmp=new NoClassDefFoundError(JAXP_MISSING_ERROR_MSG);
    tmp.initCause(error);
    throw tmp;
  }
}

代码示例来源:origin: spring-projects/spring-security

/**
   * Performs URL encoding with UTF-8
   *
   * @param value the value to URL encode
   * @return the encoded value
   */
  private String utf8UrlEncode(String value) {
    try {
      return URLEncoder.encode(value, "UTF-8");
    }
    catch (UnsupportedEncodingException e) {
      Error err = new AssertionError(
          "The Java platform guarantees UTF-8 support, but it seemingly is not present.");
      err.initCause(e);
      throw err;
    }
  }
}

代码示例来源:origin: com.h2database/h2

/**
 * Create an array of bytes with the given size. If this is not possible
 * because not enough memory is available, an OutOfMemoryError with the
 * requested size in the message is thrown.
 * <p>
 * This method should be used if the size of the array is user defined, or
 * stored in a file, so wrong size data can be distinguished from regular
 * out-of-memory.
 * </p>
 *
 * @param len the number of bytes requested
 * @return the byte array
 * @throws OutOfMemoryError if the allocation was too large
 */
public static byte[] newBytes(int len) {
  if (len == 0) {
    return EMPTY_BYTES;
  }
  try {
    return new byte[len];
  } catch (OutOfMemoryError e) {
    Error e2 = new OutOfMemoryError("Requested memory: " + len);
    e2.initCause(e);
    throw e2;
  }
}

代码示例来源:origin: com.h2database/h2

/**
 * Creates a copy of array of bytes with the new size. If this is not possible
 * because not enough memory is available, an OutOfMemoryError with the
 * requested size in the message is thrown.
 * <p>
 * This method should be used if the size of the array is user defined, or
 * stored in a file, so wrong size data can be distinguished from regular
 * out-of-memory.
 * </p>
 *
 * @param bytes source array
 * @param len the number of bytes in the new array
 * @return the byte array
 * @throws OutOfMemoryError if the allocation was too large
 * @see Arrays#copyOf(byte[], int)
 */
public static byte[] copyBytes(byte[] bytes, int len) {
  if (len == 0) {
    return EMPTY_BYTES;
  }
  try {
    return Arrays.copyOf(bytes, len);
  } catch (OutOfMemoryError e) {
    Error e2 = new OutOfMemoryError("Requested memory: " + len);
    e2.initCause(e);
    throw e2;
  }
}

代码示例来源:origin: lealone/Lealone

/**
 * Create an array of bytes with the given size. If this is not possible
 * because not enough memory is available, an OutOfMemoryError with the
 * requested size in the message is thrown.
 * <p>
 * This method should be used if the size of the array is user defined, or
 * stored in a file, so wrong size data can be distinguished from regular
 * out-of-memory.
 *
 * @param len the number of bytes requested
 * @return the byte array
 * @throws OutOfMemoryError if the allocation was too large
 */
public static byte[] newBytes(int len) {
  if (len == 0) {
    return EMPTY_BYTES;
  }
  try {
    return new byte[len];
  } catch (OutOfMemoryError e) {
    Error e2 = new OutOfMemoryError("Requested memory: " + len);
    e2.initCause(e);
    throw e2;
  }
}

代码示例来源:origin: io.netty/netty

private static void encodeTrailingHeaders(ChannelBuffer buf, HttpChunkTrailer trailer) {
  try {
    for (Map.Entry<String, String> h: trailer.trailingHeaders()) {
      encodeHeader(buf, h.getKey(), h.getValue());
    }
  } catch (UnsupportedEncodingException e) {
    throw (Error) new Error().initCause(e);
  }
}

代码示例来源:origin: io.netty/netty

private static void encodeHeaders(ChannelBuffer buf, HttpMessage message) {
  try {
    for (Map.Entry<String, String> h: message.headers()) {
      encodeHeader(buf, h.getKey(), h.getValue());
    }
  } catch (UnsupportedEncodingException e) {
    throw (Error) new Error().initCause(e);
  }
}

代码示例来源:origin: bytedeco/javacpp

e.initCause(ex);
if (logger.isDebugEnabled()) {
  logger.debug("Failed to extract for " + libnameversion + ": " + e);

代码示例来源:origin: bytedeco/javacpp

e.initCause(ex);
throw e;

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

public static SimpleFeature createAddressFeature() {
  try {
    return createFeature();
    // FeatureType addressType = createAddressType();
    // Object[] attributes = createComplexAttributes();
    // return addressType.create(attributes);
  } catch (Exception e) {
    Error ae = new AssertionError("Sample Feature for tests has been misscoded");
    ae.initCause(e);
    throw ae;
  }
}

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

public static SimpleFeature createFeature() {
  try {
    SimpleFeatureType testType = createTestType();
    Object[] attributes = createAttributes();
    return SimpleFeatureBuilder.build(testType, attributes, null);
  } catch (Exception e) {
    Error ae = new AssertionError("Sample Feature for tests has been misscoded");
    ae.initCause(e);
    throw ae;
  }
}

代码示例来源:origin: com.amazon.carbonado/carbonado

private static Method lookupMethod(Class type, String name, Class... args) {
  try {
    return type.getMethod(name, args);
  } catch (NoSuchMethodException e) {
    Error error = new NoSuchMethodError();
    error.initCause(e);
    throw error;
  }
}

代码示例来源:origin: org.apache.aries.testsupport/org.apache.aries.testsupport.unit

public String getLocation()
{
 try {
  return (location == null) ? new File(symbolicName + ".jar").toURL().toString() : location;
 } catch (MalformedURLException e) {
  Error err = new AssertionFailedError("We could not generate a valid url for the bundle");
  err.initCause(e);
  throw err;
 }
}

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

public String getLocation()
{
 try {
  return (location == null) ? new File(symbolicName + ".jar").toURL().toString() : location;
 } catch (MalformedURLException e) {
  Error err = new AssertionFailedError("We could not generate a valid url for the bundle");
  err.initCause(e);
  throw err;
 }
}

代码示例来源:origin: org.apache.aries.testsupport/org.apache.aries.testsupport.unit

public URL getResource(String name)
{
 if (cl != null) return cl.getResource(name);
 
 try {
  File f = new File(name);
  if(f.exists() || "Entities.jar".equals(name)) return f.toURL();
  else return null;
 } catch (MalformedURLException e) {
  Error err = new AssertionFailedError("The resource " + name + " could not be found.");
  err.initCause(e);
  throw err;
 }
}

代码示例来源:origin: com.atlassian.scheduler/atlassian-scheduler-core-test

protected void assertValid(final String cronExpression) {
  try {
    validator.validate(cronExpression);
  } catch (CronSyntaxException cse) {
    final Error e = new AssertionError("Expected '" + cronExpression + "' to be valid, but it threw " + cse);
    e.initCause(cse);
    throw e;
  }
}

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

public URL getResource(String name)
{
 if (cl != null) return cl.getResource(name);
 
 try {
  File f = new File(name);
  if(f.exists() || "Entities.jar".equals(name)) return f.toURL();
  else return null;
 } catch (MalformedURLException e) {
  Error err = new AssertionFailedError("The resource " + name + " could not be found.");
  err.initCause(e);
  throw err;
 }
}

代码示例来源:origin: org.apache.apex/apex-shaded-ning19

private static void encodeTrailingHeaders(ChannelBuffer buf, HttpChunkTrailer trailer) {
  try {
    for (Map.Entry<String, String> h: trailer.trailingHeaders()) {
      encodeHeader(buf, h.getKey(), h.getValue());
    }
  } catch (UnsupportedEncodingException e) {
    throw (Error) new Error().initCause(e);
  }
}

代码示例来源:origin: org.apache.apex/apex-shaded-ning19

private static void encodeHeaders(ChannelBuffer buf, HttpMessage message) {
  try {
    for (Map.Entry<String, String> h: message.headers()) {
      encodeHeader(buf, h.getKey(), h.getValue());
    }
  } catch (UnsupportedEncodingException e) {
    throw (Error) new Error().initCause(e);
  }
}

代码示例来源:origin: EvoSuite/evosuite

@Override
public synchronized Throwable initCause(Throwable cause) {
  if(!MockFramework.isEnabled()){
    return super.initCause(cause);
  }
  return getDelegate().initCause(cause);
}

相关文章