当前位置: 首页>>代码示例>>Java>>正文


Java Throwables.propagateIfPossible方法代码示例

本文整理汇总了Java中com.google.common.base.Throwables.propagateIfPossible方法的典型用法代码示例。如果您正苦于以下问题:Java Throwables.propagateIfPossible方法的具体用法?Java Throwables.propagateIfPossible怎么用?Java Throwables.propagateIfPossible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Throwables的用法示例。


在下文中一共展示了Throwables.propagateIfPossible方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
    checkNotReady();

    final DataTreeModification tree = mutableTree;
    LOG.debug("Tx: {} Merge: {}:{}", getIdentifier(), path, data);

    try {
        tree.merge(path, data);
        // FIXME: Add checked exception
    } catch (Exception e) {
        LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e);
        // Rethrow original ones if they are subclasses of RuntimeException
        // or Error
        Throwables.propagateIfPossible(e);
        // FIXME: Introduce proper checked exception
        throw new IllegalArgumentException("Illegal input data.", e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:SnapshotBackedWriteTransaction.java

示例2: close

import com.google.common.base.Throwables; //导入方法依赖的package包/类
/**
 * Closes all {@code Closeable} instances that have been added to this {@code Closer}. If an
 * exception was thrown in the try block and passed to one of the {@code exceptionThrown} methods,
 * any exceptions thrown when attempting to close a closeable will be suppressed. Otherwise, the
 * <i>first</i> exception to be thrown from an attempt to close a closeable will be thrown and any
 * additional exceptions that are thrown after that will be suppressed.
 */
@Override
public void close() throws IOException {
  Throwable throwable = thrown;

  // close closeables in LIFO order
  while (!stack.isEmpty()) {
    Closeable closeable = stack.removeFirst();
    try {
      closeable.close();
    } catch (Throwable e) {
      if (throwable == null) {
        throwable = e;
      } else {
        suppressor.suppress(closeable, throwable, e);
      }
    }
  }

  if (thrown == null && throwable != null) {
    Throwables.propagateIfPossible(throwable, IOException.class);
    throw new AssertionError(throwable); // not possible
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:31,代码来源:Closer.java

示例3: doResolveException

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
                                          Object _handler, Exception ex) {
    HandlerMethod handler = (HandlerMethod) _handler;
    if (handler == null) {
        return null;
    }
    Method method = handler.getMethod();
    if (method.isAnnotationPresent(JsonBody.class) && ex != null) {
        logger.error("server is error", ex);
        Object value = null;
        if (ex instanceof ServiceException) {
            value = new JsonResult<Object>(((ServiceException) ex).getCode(), ex.getMessage());
        } else {
            value = new JsonResult<Object>(-1, ex.getMessage());
        }
        try {
            JsonUtil.writeValue(response.getWriter(), value);
        } catch (IOException e) {
            Throwables.propagateIfPossible(e);
        }
        return ModelAndViewResolver.UNRESOLVED;
    }
    return null;
}
 
开发者ID:didapinchegit,项目名称:rocket-console,代码行数:26,代码来源:JsonBodyExceptionResolver.java

示例4: delete

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
public void delete(final YangInstanceIdentifier path) {
    checkNotReady();

    final DataTreeModification tree = mutableTree;
    LOG.debug("Tx: {} Delete: {}", getIdentifier(), path);

    try {
        tree.delete(path);
        // FIXME: Add checked exception
    } catch (Exception e) {
        LOG.error("Tx: {}, failed to delete {} in {}", getIdentifier(), path, tree, e);
        // Rethrow original ones if they are subclasses of RuntimeException
        // or Error
        Throwables.propagateIfPossible(e);
        // FIXME: Introduce proper checked exception
        throw new IllegalArgumentException("Illegal path to delete.", e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:SnapshotBackedWriteTransaction.java

示例5: propagateReadFailedExceptionCause

import com.google.common.base.Throwables; //导入方法依赖的package包/类
protected void propagateReadFailedExceptionCause(final CheckedFuture<?, ReadFailedException> future)
        throws Exception {
    try {
        future.checkedGet(5, TimeUnit.SECONDS);
        fail("Expected ReadFailedException");
    } catch (ReadFailedException e) {
        assertNotNull("Expected a cause", e.getCause());
        Throwable cause;
        if (e.getCause().getCause() != null) {
            cause = e.getCause().getCause();
        } else {
            cause = e.getCause();
        }

        Throwables.propagateIfPossible(cause, Exception.class);
        throw new RuntimeException(cause);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:AbstractTransactionProxyTest.java

示例6: propagateExecutionExceptionCause

import com.google.common.base.Throwables; //导入方法依赖的package包/类
private void propagateExecutionExceptionCause(final ListenableFuture<?> future) throws Exception {

        try {
            future.get(5, TimeUnit.SECONDS);
            fail("Expected ExecutionException");
        } catch (ExecutionException e) {
            verifyCohortActors();
            Throwables.propagateIfPossible(e.getCause(), Exception.class);
            throw new RuntimeException(e.getCause());
        }
    }
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:ThreePhaseCommitCohortProxyTest.java

示例7: writeValue

import com.google.common.base.Throwables; //导入方法依赖的package包/类
public static void writeValue(Writer writer, Object obj) {
    try {
        objectMapper.writeValue(writer, obj);
    } catch (IOException e) {
        Throwables.propagateIfPossible(e);
    }
}
 
开发者ID:didapinchegit,项目名称:rocket-console,代码行数:8,代码来源:JsonUtil.java

示例8: loadSchemas

import com.google.common.base.Throwables; //导入方法依赖的package包/类
public void loadSchemas(final Class<?>... classes) {
    YangModuleInfo moduleInfo;
    try {
        final ModuleInfoBackedContext context = ModuleInfoBackedContext.create();
        for (final Class<?> clz : classes) {
            moduleInfo = BindingReflections.getModuleInfo(clz);

            context.registerModuleInfo(moduleInfo);
        }
        this.schemaContext = context.tryToCreateSchemaContext().get();
        this.domStore.onGlobalContextUpdated(this.schemaContext);
    } catch (final Exception e) {
        Throwables.propagateIfPossible(e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:16,代码来源:SchemaUpdateForTransactionTest.java

示例9: close

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
  closed = true;
  if (throwOnClose != null) {
    Throwables.propagateIfPossible(throwOnClose, IOException.class);
    throw new AssertionError(throwOnClose);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:CloserTest.java

示例10: testBatchedModificationsReadyWithIncorrectTotalMessageCount

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
    new ShardTestKit(getSystem()) {
        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(
                    newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
                    "testBatchedModificationsReadyWithIncorrectTotalMessageCount");

            waitUntilLeader(shard);

            final TransactionIdentifier transactionID = nextTransactionId();
            final BatchedModifications batched = new BatchedModifications(transactionID,
                    DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);

            shard.tell(batched, getRef());

            final Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);

            if (failure != null) {
                Throwables.propagateIfPossible(failure.cause(), Exception.class);
                throw new RuntimeException(failure.cause());
            }
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:28,代码来源:ShardTest.java

示例11: run

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
public final void run() {
  try {
    doRun();
  } catch (final Exception ex) {
    logger.error("failed to execute task", ex);
    exception.addException(ex);
    Throwables.propagateIfPossible(ex);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:AsyncTask.java

示例12: maybeInitialize

import com.google.common.base.Throwables; //导入方法依赖的package包/类
private void maybeInitialize() throws IOException {
  if (initialized) {
    return;
  }
  checkState(data == null);
  checkState(offset == 0);
  checkState(chunkCache == null);
  try {
    data = dataSupplier.get();
  } catch (RuntimeException e) {
    Throwables.propagateIfPossible(e.getCause(), IOException.class);
    throw e;
  }
  initialized = true;
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:16,代码来源:Chunker.java

示例13: nextOpImpl

import com.google.common.base.Throwables; //导入方法依赖的package包/类
private FSEditLogOp nextOpImpl(boolean skipBrokenEdits) throws IOException {
  FSEditLogOp op = null;
  switch (state) {
  case UNINIT:
    try {
      init(true);
    } catch (Throwable e) {
      LOG.error("caught exception initializing " + this, e);
      if (skipBrokenEdits) {
        return null;
      }
      Throwables.propagateIfPossible(e, IOException.class);
    }
    Preconditions.checkState(state != State.UNINIT);
    return nextOpImpl(skipBrokenEdits);
  case OPEN:
    op = reader.readOp(skipBrokenEdits);
    if ((op != null) && (op.hasTransactionId())) {
      long txId = op.getTransactionId();
      if ((txId >= lastTxId) &&
          (lastTxId != HdfsConstants.INVALID_TXID)) {
        //
        // Sometimes, the NameNode crashes while it's writing to the
        // edit log.  In that case, you can end up with an unfinalized edit log
        // which has some garbage at the end.
        // JournalManager#recoverUnfinalizedSegments will finalize these
        // unfinished edit logs, giving them a defined final transaction 
        // ID.  Then they will be renamed, so that any subsequent
        // readers will have this information.
        //
        // Since there may be garbage at the end of these "cleaned up"
        // logs, we want to be sure to skip it here if we've read everything
        // we were supposed to read out of the stream.
        // So we force an EOF on all subsequent reads.
        //
        long skipAmt = log.length() - tracker.getPos();
        if (skipAmt > 0) {
          if (LOG.isDebugEnabled()) {
              LOG.debug("skipping " + skipAmt + " bytes at the end " +
                "of edit log  '" + getName() + "': reached txid " + txId +
                " out of " + lastTxId);
          }
          tracker.clearLimit();
          IOUtils.skipFully(tracker, skipAmt);
        }
      }
    }
    break;
    case CLOSED:
      break; // return null
  }
  return op;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:54,代码来源:EditLogFileInputStream.java

示例14: pump

import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
public Result pump() {
  try{
    switch(sink.getState().getMasterState()){

    case CAN_CONSUME: {
      switch(source.getState().getMasterState()){
      case CAN_PRODUCE:
        final int recordCount = source.outputData();
        // consume data if more than zero records.
        if(recordCount > 0){
          sink.consumeData(recordCount);
        }
        return Result.PUMPED;
      case DONE:
        sink.noMoreToConsume();
        upstream = null;
        return Result.DONE;

      default:
        return Result.NOT_READY_UPSTREAM;

      }
    }

    // this pipe is blocked on downstream.
    case CAN_PRODUCE:
    case BLOCKED:
      return Result.NOT_READY_DOWNSTREAM;

    case DONE:
      return Result.DONE;

    case CAN_CONSUME_L:
    case CAN_CONSUME_R:
    case NEEDS_SETUP:
    default:
      throw new IllegalStateException("Invalid state: " + sink.getState());

    }

  }catch(Exception ex){
    Throwables.propagateIfPossible(ex, UserException.class);
    throw new PipeFailure(this, ex);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:47,代码来源:StraightPipe.java

示例15: rethrow

import com.google.common.base.Throwables; //导入方法依赖的package包/类
/**
 * Stores the given throwable and rethrows it. It will be rethrown as is if it is an
 * {@code IOException}, {@code RuntimeException} or {@code Error}. Otherwise, it will be rethrown
 * wrapped in a {@code RuntimeException}. <b>Note:</b> Be sure to declare all of the checked
 * exception types your try block can throw when calling an overload of this method so as to avoid
 * losing the original exception type.
 *
 * <p>This method always throws, and as such should be called as {@code throw closer.rethrow(e);}
 * to ensure the compiler knows that it will throw.
 *
 * @return this method does not return; it always throws
 * @throws IOException when the given throwable is an IOException
 */
public RuntimeException rethrow(Throwable e) throws IOException {
  checkNotNull(e);
  thrown = e;
  Throwables.propagateIfPossible(e, IOException.class);
  throw new RuntimeException(e);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:Closer.java


注:本文中的com.google.common.base.Throwables.propagateIfPossible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。