本文整理匯總了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);
}
}
示例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
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
};
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}