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

x33g5p2x  于2022-01-16 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(173)

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

RuntimeException.initCause介绍

暂无

代码示例

代码示例来源:origin: org.osgi/org.osgi.compendium

/**
   * Initializes the cause of this exception to the specified value.
   * 
   * @param cause The cause of this exception.
   * @return This exception.
   * @throws IllegalArgumentException If the specified cause is this
   *         exception.
   * @throws IllegalStateException If the cause of this exception has already
   *         been set.
   */
  public Throwable initCause(Throwable cause) {
    return super.initCause(cause);
  }
}

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

public UnknownUnwrapTypeException(Class unwrapType, Throwable root) {
  this( unwrapType );
  super.initCause( root );
}

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

public String firstLine(BufferedReader r) {
  try {
    return r.readLine();
  } catch (IOException e) {
    throw (RuntimeException) new RuntimeException("IO Error").initCause(e);
  }
}

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

/**
 * Generates XML and writes it to the given <code>PrintWriter</code>
 */
private void generate(PrintWriter pw) {
 // Use JAXP's transformation API to turn SAX events into pretty
 // XML text
 try {
  Source src = new SAXSource(this, new InputSource());
  Result res = new StreamResult(pw);
  TransformerFactory xFactory = TransformerFactory.newInstance();
  Transformer xform = xFactory.newTransformer();
  xform.setOutputProperty(OutputKeys.METHOD, "xml");
  xform.setOutputProperty(OutputKeys.INDENT, "yes");
  xform.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, SYSTEM_ID);
  xform.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, PUBLIC_ID);
  xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
  xform.transform(src, res);
  pw.flush();
 } catch (Exception ex) {
  RuntimeException ex2 = new RuntimeException(
    "Exception thrown while generating XML.");
  ex2.initCause(ex);
  throw ex2;
 }
}

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

private static <T> T getFuture(final String comment, final Future<T> future) {
 try {
  return Uninterruptibles.getUninterruptibly(future);
  // No need to catch cancellationexception - we never cancel these futures
 } catch (ExecutionException e) {
  Throwable t = e.getCause();
  if (t instanceof SQLiteException) {
   final RuntimeException sqlException = getSqliteException("Cannot " + comment, ((SQLiteException) t).getBaseErrorCode());
   sqlException.initCause(e);
   throw sqlException;
  } else {
   throw new RuntimeException(e);
  }
 }
}

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

/**
 * Writes the generator's state to pw
 */
private void generate(PrintWriter pw) {
 // Use JAXP's transformation API to turn SAX events into pretty
 // XML text
 try {
  Source src = new SAXSource(this, new InputSource());
  Result res = new StreamResult(pw);
  TransformerFactory xFactory = TransformerFactory.newInstance();
  Transformer xform = xFactory.newTransformer();
  xform.setOutputProperty(OutputKeys.METHOD, "xml");
  xform.setOutputProperty(OutputKeys.INDENT, "yes");
  if (!useSchema) {
   // set the doctype system and public ids from version for older DTDs.
   xform.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, version.getSystemId());
   xform.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, version.getPublicId());
  }
  xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
  xform.transform(src, res);
  pw.flush();
 } catch (Exception ex) {
  RuntimeException ex2 = new RuntimeException(
    "An Exception was thrown while generating XML.");
  ex2.initCause(ex);
  throw ex2;
 }
}

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

", but in the past before";
RuntimeException ex = new RuntimeException(message);
ex.initCause(e);
ex.printStackTrace(System.out);

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

/** {@inheritDoc} */
@Override public T get() throws ExecutionException {
  try {
    T res = fut.get();
    if (fut.isCancelled())
      throw new CancellationException("Task was cancelled: " + fut);
    return res;
  }
  catch (IgniteCheckedException e) {
    // Task cancellation may cause throwing exception.
    if (fut.isCancelled()) {
      RuntimeException ex = new CancellationException("Task was cancelled: " + fut);
      ex.initCause(e);
      throw ex;
    }
    throw new ExecutionException("Failed to get task result: " + fut, e);
  }
}

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

public int calcSerializedSize() {
 NullDataOutputStream dos = new NullDataOutputStream();
 try {
  toData(dos);
  return dos.size();
 } catch (IOException ex) {
  RuntimeException ex2 = new IllegalArgumentException(
    "Could not calculate size of object");
  ex2.initCause(ex);
  throw ex2;
 }
}

代码示例来源:origin: knightliao/disconf

LOG.warn("Caught: " + e, e);
  throw (RuntimeException) new RuntimeException(e.getMessage()).
                                   initCause(e);
} finally {
  if (callback != null) {

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

LOG.warn("Caught: " + e, e);
throw (RuntimeException) new RuntimeException(e.getMessage()).
  initCause(e);

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

/** {@inheritDoc} */
  @Override public T get(long timeout, TimeUnit unit) throws ExecutionException, TimeoutException {
    A.ensure(timeout >= 0, "timeout >= 0");
    A.notNull(unit, "unit != null");
    try {
      T res = fut.get(unit.toMillis(timeout));
      if (fut.isCancelled())
        throw new CancellationException("Task was cancelled: " + fut);
      return res;
    }
    catch (IgniteFutureTimeoutCheckedException e) {
      TimeoutException e2 = new TimeoutException();
      e2.initCause(e);
      throw e2;
    }
    catch (ComputeTaskTimeoutCheckedException e) {
      throw new ExecutionException("Task execution timed out during waiting for task result: " + fut, e);
    }
    catch (IgniteCheckedException e) {
      // Task cancellation may cause throwing exception.
      if (fut.isCancelled()) {
        RuntimeException ex = new CancellationException("Task was cancelled: " + fut);
        ex.initCause(e);
        throw ex;
      }
      throw new ExecutionException("Failed to get task result.", e);
    }
  }
}

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

@Override
public boolean containsValueForKey(KeyInfo keyInfo) {
 try {
  boolean retVal = region.containsValueForKeyRemotely(
    (InternalDistributedMember) state.getTarget(), keyInfo.getBucketId(), keyInfo.getKey());
  trackBucketForTx(keyInfo);
  return retVal;
 } catch (TransactionException e) {
  RuntimeException re = getTransactionException(keyInfo, e);
  re.initCause(e.getCause());
  throw re;
 } catch (PrimaryBucketException e) {
  RuntimeException re = getTransactionException(keyInfo, e);
  re.initCause(e);
  throw re;
 } catch (ForceReattemptException e) {
  if (isBucketNotFoundException(e)) {
   RuntimeException re = getTransactionException(keyInfo, e);
   re.initCause(e);
   throw re;
  }
  waitToRetry();
  RuntimeException re = new TransactionDataNodeHasDepartedException(
    String.format(
      "Transaction data node %s has departed. To proceed, rollback this transaction and begin a new one.",
      state.getTarget()));
  re.initCause(e);
  throw re;
 }
}

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

@Override
public boolean containsKey(KeyInfo keyInfo) {
 try {
  boolean retVal = region.containsKeyRemotely((InternalDistributedMember) state.getTarget(),
    keyInfo.getBucketId(), keyInfo.getKey());
  trackBucketForTx(keyInfo);
  return retVal;
 } catch (TransactionException e) {
  RuntimeException re = getTransactionException(keyInfo, e);
  re.initCause(e.getCause());
  throw re;
 } catch (PrimaryBucketException e) {
  RuntimeException re = getTransactionException(keyInfo, e);
  re.initCause(e);
  throw re;
 } catch (ForceReattemptException e) {
  if (isBucketNotFoundException(e)) {
   RuntimeException re = getTransactionException(keyInfo, e);
   re.initCause(e);
   throw re;
  }
  waitToRetry();
  RuntimeException re = new TransactionDataNodeHasDepartedException(
    String.format(
      "Transaction data node %s has departed. To proceed, rollback this transaction and begin a new one.",
      state.getTarget()));
  re.initCause(e);
  throw re;
 }
}

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

public void run() {
    try {
      servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
                               ServerTestUtils.createServerConfig(useNio,
                                                j,
                                                TestUtils.createTempDir()
                                                     .getAbsolutePath(),
                                                null,
                                                storesXmlfile,
                                                props),
                               cluster));
    } catch(IOException ioe) {
      logger.error("Caught IOException during parallel server start: "
             + ioe.getMessage());
      RuntimeException re = new RuntimeException();
      re.initCause(ioe);
      throw re;
    } finally {
      // Ensure setup progresses in face of errors
      countDownLatch.countDown();
    }
  }
});

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

@Override
public boolean putEntry(EntryEventImpl event, boolean ifNew, boolean ifOld,
  Object expectedOldValue, boolean requireOldValue, long lastModified,
  boolean overwriteDestroyed) {
 boolean retVal = false;
 final InternalRegion r = event.getRegion();
 PartitionedRegion pr = (PartitionedRegion) r;
 try {
  retVal =
    pr.putRemotely(state.getTarget(), event, ifNew, ifOld, expectedOldValue, requireOldValue);
 } catch (TransactionException e) {
  RuntimeException re = getTransactionException(event.getKeyInfo(), e);
  re.initCause(e.getCause());
  throw re;
 } catch (PrimaryBucketException e) {
  RuntimeException re = getTransactionException(event.getKeyInfo(), e);
  re.initCause(e);
  throw re;
 } catch (ForceReattemptException e) {
  waitToRetry();
  RuntimeException re = getTransactionException(event.getKeyInfo(), e);
  re.initCause(e);
  throw re;
 }
 trackBucketForTx(event.getKeyInfo());
 return retVal;
}

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

} catch (TransactionException e) {
 RuntimeException re = getTransactionException(event.getKeyInfo(), e);
 re.initCause(e.getCause());
 throw re;
} catch (PrimaryBucketException e) {
 RuntimeException re = getTransactionException(event.getKeyInfo(), e);
 re.initCause(e);
 throw re;
} catch (ForceReattemptException e) {
      state.getTarget()));
 re.initCause(e);
 waitToRetry();
 throw re;

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

@Override
 public RuntimeException generateCancelledException(Throwable e) {
  String reason = cancelInProgress();
  if (reason == null) {
   return null;
  }
  DistributionManager dm = getDM();
  if (dm == null) {
   return new DistributedSystemDisconnectedException("no distribution manager");
  }
  RuntimeException result = dm.getCancelCriterion().generateCancelledException(e);
  if (result != null) {
   return result;
  }
  // We know we've been stopped; generate the exception
  result = new DistributedSystemDisconnectedException("Conduit has been stopped");
  result.initCause(e);
  return result;
 }
}

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

private VersionedObjectList sendMsgByBucket(final Integer bucketId, RemoveAllPRMessage prMsg,
  PartitionedRegion pr) {
 // retry the put remotely until it finds the right node managing the bucket
 InternalDistributedMember currentTarget =
   pr.getOrCreateNodeForBucketWrite(bucketId.intValue(), null);
 if (!currentTarget.equals(this.state.getTarget())) {
  @Released
  EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
  try {
   throw new TransactionDataNotColocatedException(
     String.format("Key %s is not colocated with transaction",
       firstEvent.getKey()));
  } finally {
   firstEvent.release();
  }
 }
 try {
  return pr.tryToSendOneRemoveAllMessage(prMsg, currentTarget);
 } catch (ForceReattemptException prce) {
  pr.checkReadiness();
  throw new TransactionDataNotColocatedException(prce.getMessage());
 } catch (PrimaryBucketException notPrimary) {
  RuntimeException re = new TransactionDataRebalancedException(
    "Transactional data moved, due to rebalancing.");
  re.initCause(notPrimary);
  throw re;
 } catch (DataLocationException dle) {
  throw new TransactionException(dle);
 }
}

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

private VersionedObjectList sendMsgByBucket(final Integer bucketId, PutAllPRMessage prMsg,
  PartitionedRegion pr) {
 // retry the put remotely until it finds the right node managing the bucket
 InternalDistributedMember currentTarget =
   pr.getOrCreateNodeForBucketWrite(bucketId.intValue(), null);
 if (!currentTarget.equals(this.state.getTarget())) {
  @Released
  EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
  try {
   throw new TransactionDataNotColocatedException(
     String.format("Key %s is not colocated with transaction",
       firstEvent.getKey()));
  } finally {
   firstEvent.release();
  }
 }
 try {
  return pr.tryToSendOnePutAllMessage(prMsg, currentTarget);
 } catch (ForceReattemptException prce) {
  pr.checkReadiness();
  throw new TransactionDataNotColocatedException(prce.getMessage());
 } catch (PrimaryBucketException notPrimary) {
  RuntimeException re = new TransactionDataRebalancedException(
    "Transactional data moved, due to rebalancing.");
  re.initCause(notPrimary);
  throw re;
 } catch (DataLocationException dle) {
  throw new TransactionException(dle);
 }
}

相关文章