public static <V, X extends Exception> V get(
      Future<V> future, Class<X> exceptionClass) throws X {
    checkNotNull(future);
    checkArgument(!RuntimeException.class.isAssignableFrom(exceptionClass),
        "Futures.get exception type (%s) must not be a RuntimeException",
        exceptionClass);
    try {
      return future.get();
    } catch (InterruptedException e) {
      currentThread().interrupt();
      throw newWithCause(exceptionClass, e);
    } catch (ExecutionException e) {
      wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
      throw new AssertionError();
    }
  }
public static < V , X extends Exception > V get ( Future < V > future , Class < X > exceptionClass ) throws X { checkNotNull ( future ) ; checkArgument ( ! RuntimeException . class . isAssignableFrom ( exceptionClass ) , "Futures.get exception type (%s) must not be a RuntimeException" , exceptionClass ) ; try { return future . get ( ) ; } catch ( InterruptedException e ) { currentThread ( ) . interrupt ( ) ; throw newWithCause ( exceptionClass , e ) ; } catch ( ExecutionException e ) { wrapAndThrowExceptionOrError ( e . getCause ( ) , exceptionClass ) ; throw new AssertionError ( ) ; } }
Returns the result of {@link Future#get()}, converting most exceptions to a
new instance of the given checked exception type. This reduces boilerplate
for a common use of {@code Future} in which it is unnecessary to
programmatically distinguish between exception types or to extract other
information from the exception instance.

<p>Exceptions from {@code Future.get} are treated as follows:
<ul>
<li>Any {@link ExecutionException} has its <i>cause</i> wrapped in an
{@code X} if the cause is a checked exception, an {@link
UncheckedExecutionException} if the cause is a {@code
RuntimeException}, or an {@link ExecutionError} if the cause is an
{@code Error}.
<li>Any {@link InterruptedException} is wrapped in an {@code X} (after
restoring the interrupt).
<li>Any {@link CancellationException} is propagated untouched, as is any
other {@link RuntimeException} (though {@code get} implementations are
discouraged from throwing such exceptions).
</ul>

<p>The overall principle is to continue to treat every checked exception as a
checked exception, every unchecked exception as an unchecked exception, and
every error as an error. In addition, the cause of any {@code
ExecutionException} is wrapped in order to ensure that the new stack trace
matches that of the current thread.

<p>Instances of {@code exceptionClass} are created by choosing an arbitrary
public constructor that accepts zero or more arguments, all of type {@code
String} or {@code Throwable} (preferring constructors with at least one
{@code String}) and calling the constructor via reflection. If the
exception did not already have a cause, one is set by calling {@link
Throwable#initCause(Throwable)} on it. If no such constructor exists, an
{@code IllegalArgumentException} is thrown.

@throws X if {@code get} throws any checked exception except for an {@code
ExecutionException} whose cause is not itself a checked exception
@throws UncheckedExecutionException if {@code get} throws an {@code
ExecutionException} with a {@code RuntimeException} as its cause
@throws ExecutionError if {@code get} throws an {@code ExecutionException}
with an {@code Error} as its cause
@throws CancellationException if {@code get} throws a {@code
CancellationException}
@throws IllegalArgumentException if {@code exceptionClass} extends {@code
RuntimeException} or does not have a suitable constructor
@since 10.0