本文整理了Java中com.google.common.util.concurrent.UncheckedExecutionException
类的一些代码示例,展示了UncheckedExecutionException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UncheckedExecutionException
类的具体详情如下:
包路径:com.google.common.util.concurrent.UncheckedExecutionException
类名称:UncheckedExecutionException
[英]Unchecked variant of java.util.concurrent.ExecutionException. As with ExecutionException, the exception's #getCause() comes from a failed task, possibly run in another thread.
UncheckedExecutionException is intended as an alternative to ExecutionException when the exception thrown by a task is an unchecked exception. However, it may also wrap a checked exception in some cases.
When wrapping an Error from another thread, prefer ExecutionError. When wrapping a checked exception, prefer ExecutionException.
[中]未经检查的java变体。util。同时发生的死刑例外。与ExecutionException一样,异常的#getCause()来自失败的任务,可能在另一个线程中运行。
当任务引发的异常是未检查的异常时,UncheckedExecutionException是ExecutionException的替代方案。然而,在某些情况下,它也可能包装一个选中的异常。
当包装来自另一个线程的错误时,首选ExecutionError。包装选中的异常时,首选ExecutionException。
代码示例来源:origin: apache/pulsar
public static TopicName get(String topic) {
try {
return cache.get(topic);
} catch (ExecutionException e) {
throw (RuntimeException) e.getCause();
} catch (UncheckedExecutionException e) {
throw (RuntimeException) e.getCause();
}
}
代码示例来源:origin: google/guava
@Override
public V getUnchecked(K key) {
try {
return get(key);
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e.getCause());
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public T get() {
try {
return cache.get("FOO").orNull();
} catch (UncheckedExecutionException e) {
throw propagate(e.getCause());
} catch (ExecutionException e) {
throw propagate(e.getCause());
}
}
代码示例来源:origin: ben-manes/caffeine
LoadingCache<Object, Object> cache = CaffeinatedGuava.build(
Caffeine.newBuilder().recordStats().executor(MoreExecutors.directExecutor()), loader);
CacheStats stats = cache.stats();
assertEquals(0, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
cache.get(new Object());
fail();
} catch (ExecutionException expected) {
assertSame(e, expected.getCause());
stats = cache.stats();
assertEquals(1, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
fail();
} catch (UncheckedExecutionException expected) {
assertSame(e, expected.getCause());
fail();
} catch (ExecutionException expected) {
assertSame(callableException, expected.getCause());
fail();
} catch (ExecutionException expected) {
assertSame(e, expected.getCause());
代码示例来源:origin: ben-manes/caffeine
final UncheckedExecutionException uee = new UncheckedExecutionException(cause);
final ExecutionException ee = new ExecutionException(cause);
cacheUnchecked.get(new Object());
fail();
} catch (UncheckedExecutionException caughtEe) {
assertSame(uee, caughtEe.getCause());
cacheUnchecked.getUnchecked(new Object());
fail();
} catch (UncheckedExecutionException caughtUee) {
assertSame(uee, caughtUee.getCause());
cacheUnchecked.refresh(new Object());
checkLoggedCause(uee);
fail();
} catch (UncheckedExecutionException caughtEe) {
assertSame(uee, caughtEe.getCause());
fail();
} catch (ExecutionException caughtEe) {
assertSame(ee, caughtEe.getCause());
fail();
} catch (UncheckedExecutionException caughtUee) {
assertSame(ee, caughtUee.getCause());
代码示例来源:origin: google/guava
/**
* Flattens a class's type hierarchy into a set of {@code Class} objects including all
* superclasses (transitively) and all interfaces implemented by these superclasses.
*/
@VisibleForTesting
static ImmutableSet<Class<?>> flattenHierarchy(Class<?> concreteClass) {
try {
return flattenHierarchyCache.getUnchecked(concreteClass);
} catch (UncheckedExecutionException e) {
throw Throwables.propagate(e.getCause());
}
}
代码示例来源:origin: google/guava
Throwable cause = ee.getCause();
if (cause instanceof Error) {
throw new ExecutionError((Error) cause);
} else if (cause instanceof RuntimeException) {
throw new UncheckedExecutionException(cause);
代码示例来源:origin: ben-manes/caffeine
public void testBulkLoadingExceptionWithCause() throws ExecutionException {
final Exception cause = new Exception();
final UncheckedExecutionException uee = new UncheckedExecutionException(cause);
final ExecutionException ee = new ExecutionException(cause);
LoadingCache<Object, Object> cacheUnchecked =
CaffeinatedGuava.build(Caffeine.newBuilder(), bulkLoader(exceptionLoader(uee)));
LoadingCache<Object, Object> cacheChecked =
CaffeinatedGuava.build(Caffeine.newBuilder(), bulkLoader(exceptionLoader(ee)));
try {
cacheUnchecked.getAll(asList(new Object()));
fail();
} catch (UncheckedExecutionException caughtEe) {
assertSame(uee, caughtEe.getCause());
}
try {
cacheChecked.getAll(asList(new Object()));
fail();
} catch (ExecutionException caughtEe) {
assertSame(ee, caughtEe.getCause());
}
}
代码示例来源:origin: google/guava
private void wrapAndThrowExecutionExceptionOrError(Throwable cause) throws ExecutionException {
if (cause instanceof Error) {
throw new ExecutionError((Error) cause);
} else if (cause instanceof RuntimeException) {
throw new UncheckedExecutionException(cause);
} else {
throw new ExecutionException(cause);
}
}
代码示例来源:origin: ben-manes/caffeine
if (mod == 0) {
assertTrue(result.get(i) instanceof ExecutionException);
assertSame(e, ((ExecutionException) result.get(i)).getCause());
} else {
assertTrue(result.get(i) instanceof UncheckedExecutionException);
assertSame(e, ((UncheckedExecutionException) result.get(i)).getCause());
cache.getUnchecked("bar");
fail();
} catch (UncheckedExecutionException expected) {
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public ListenableFuture<DriveInfo> apply(String input) {
try {
return Futures.immediateFuture(cache.getUnchecked(input));
} catch (CacheLoader.InvalidCacheLoadException e) {
logger.debug("drive %s not found", input);
} catch (UncheckedExecutionException e) {
logger.warn(e, "error finding drive %s: %s", input, e.getMessage());
}
return Futures.immediateFuture(null);
}
代码示例来源:origin: prestodb/presto
private static <K, V> V get(LoadingCache<K, V> cache, K key)
{
try {
return cache.getUnchecked(key);
}
catch (UncheckedExecutionException e) {
throwIfInstanceOf(e.getCause(), PrestoException.class);
throw e;
}
}
代码示例来源:origin: google/guava
final UncheckedExecutionException uee = new UncheckedExecutionException(cause);
final ExecutionException ee = new ExecutionException(cause);
cacheUnchecked.get(new Object());
fail();
} catch (ExecutionException e) {
cacheUnchecked.getUnchecked(new Object());
fail();
} catch (UncheckedExecutionException caughtUee) {
cacheUnchecked.refresh(new Object());
checkLoggedCause(uee);
代码示例来源:origin: rakam-io/rakam
public boolean login(String username, String password) {
try {
Credentials key = new Credentials(username, password);
authenticationCache.refresh(key);
authenticationCache.get(key);
} catch (UncheckedExecutionException e) {
throw Throwables.propagate(e.getCause());
} catch (ExecutionException e) {
return false;
}
return true;
}
代码示例来源:origin: rakam-io/rakam
@Override
public void checkAccess(int userId) {
try (Handle handle = dbi.open()) {
Boolean exists = handle.createQuery("select email, password from web_user where id = :id")
.bind("id", userId).map((index, r, ctx) -> {
String email = r.getString(1);
String password = r.getString(2);
try {
Principal principal = authenticationCache.get(new Credentials(email, password));
if (principal == null) {
throw new RakamException("LDAP user doesn't exist", FORBIDDEN);
}
} catch (UncheckedExecutionException e) {
throw Throwables.propagate(e.getCause());
} catch (ExecutionException e) {
throw new RakamException("LDAP user doesn't exist", FORBIDDEN);
}
return Boolean.TRUE;
}).first();
if (!Boolean.TRUE.equals(exists)) {
throw new RakamException("LDAP user doesn't exist in database", FORBIDDEN);
}
}
}
代码示例来源:origin: prestodb/presto
@Override
public Type getType(TypeSignature signature)
{
Type type = types.get(signature);
if (type == null) {
try {
return parametricTypeCache.getUnchecked(signature);
}
catch (UncheckedExecutionException e) {
throwIfUnchecked(e.getCause());
throw new RuntimeException(e.getCause());
}
}
return type;
}
代码示例来源:origin: google/error-prone
public static InferredNullability getInferredNullability(Tree methodOrInitializerOrLambda) {
checkArgument(
methodOrInitializerOrLambda instanceof MethodTree
|| methodOrInitializerOrLambda instanceof LambdaExpressionTree
|| methodOrInitializerOrLambda instanceof BlockTree
|| methodOrInitializerOrLambda instanceof VariableTree,
"Tree `%s` is not a lambda, initializer, or method.",
methodOrInitializerOrLambda);
try {
return inferenceCache.getUnchecked(methodOrInitializerOrLambda);
} catch (UncheckedExecutionException e) {
throw e.getCause() instanceof CompletionFailure ? (CompletionFailure) e.getCause() : e;
}
}
代码示例来源:origin: ben-manes/caffeine
@Override
public V get(K key) {
try {
return cache.get(key);
} catch (UncheckedExecutionException e) {
if (e.getCause() instanceof CacheMissException) {
return null;
}
throw (RuntimeException) e.getCause();
} catch (ExecutionException e) {
throw new CompletionException(e);
} catch (ExecutionError e) {
throw (Error) e.getCause();
}
}
代码示例来源:origin: google/guava
public void testBulkLoadingExceptionWithCause() {
final Exception cause = new Exception();
final UncheckedExecutionException uee = new UncheckedExecutionException(cause);
final ExecutionException ee = new ExecutionException(cause);
LoadingCache<Object, Object> cacheUnchecked =
CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(uee)));
LoadingCache<Object, Object> cacheChecked =
CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(ee)));
try {
cacheUnchecked.getAll(asList(new Object()));
fail();
} catch (ExecutionException e) {
fail();
} catch (UncheckedExecutionException caughtEe) {
assertThat(caughtEe).hasCauseThat().isSameAs(uee);
}
try {
cacheChecked.getAll(asList(new Object()));
fail();
} catch (ExecutionException caughtEe) {
assertThat(caughtEe).hasCauseThat().isSameAs(ee);
}
}
代码示例来源:origin: prestodb/presto
private static <K, V> Map<K, V> getAll(LoadingCache<K, V> cache, Iterable<K> keys)
{
try {
return cache.getAll(keys);
}
catch (ExecutionException | UncheckedExecutionException e) {
throwIfInstanceOf(e.getCause(), PrestoException.class);
throwIfUnchecked(e);
throw new UncheckedExecutionException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!