Example usage for com.google.common.util.concurrent UncheckedExecutionException UncheckedExecutionException

List of usage examples for com.google.common.util.concurrent UncheckedExecutionException UncheckedExecutionException

Introduction

In this page you can find the example usage for com.google.common.util.concurrent UncheckedExecutionException UncheckedExecutionException.

Prototype

public UncheckedExecutionException(@Nullable Throwable cause) 

Source Link

Document

Creates a new instance with the given cause.

Usage

From source file:com.sk89q.guavabackport.cache.LocalCache.java

@Nullable
Map<K, V> loadAll(final Set<? extends K> keys, final CacheLoader<? super K, V> loader)
        throws ExecutionException {
    Preconditions.checkNotNull((Object) loader);
    Preconditions.checkNotNull((Object) keys);
    final Stopwatch stopwatch = Stopwatch.createStarted();
    boolean success = false;
    Map<K, V> result;/*from w  w  w  .j  av  a  2s .  co m*/
    try {
        final Map<K, V> map = result = (Map<K, V>) loader.loadAll(keys);
        success = true;
    } catch (CacheLoader.UnsupportedLoadingOperationException e) {
        success = true;
        throw e;
    } catch (InterruptedException e2) {
        Thread.currentThread().interrupt();
        throw new ExecutionException(e2);
    } catch (RuntimeException e3) {
        throw new UncheckedExecutionException((Throwable) e3);
    } catch (Exception e4) {
        throw new ExecutionException(e4);
    } catch (Error e5) {
        throw new ExecutionError(e5);
    } finally {
        if (!success) {
            this.globalStatsCounter.recordLoadException(stopwatch.elapsed(TimeUnit.NANOSECONDS));
        }
    }
    if (result == null) {
        this.globalStatsCounter.recordLoadException(stopwatch.elapsed(TimeUnit.NANOSECONDS));
        throw new CacheLoader.InvalidCacheLoadException(loader + " returned null map from loadAll");
    }
    stopwatch.stop();
    boolean nullsPresent = false;
    for (final Map.Entry<K, V> entry : result.entrySet()) {
        final K key = entry.getKey();
        final V value = entry.getValue();
        if (key == null || value == null) {
            nullsPresent = true;
        } else {
            this.put(key, value);
        }
    }
    if (nullsPresent) {
        this.globalStatsCounter.recordLoadException(stopwatch.elapsed(TimeUnit.NANOSECONDS));
        throw new CacheLoader.InvalidCacheLoadException(loader + " returned null keys or values from loadAll");
    }
    this.globalStatsCounter.recordLoadSuccess(stopwatch.elapsed(TimeUnit.NANOSECONDS));
    return result;
}