Here you can find the source of unwrap(Throwable throwable, Class throwableA)
Parameter | Description |
---|---|
throwable | Throwable to unwrap. |
throwableA | Checked Exception to expose. |
A | Class of checked exception. |
Parameter | Description |
---|---|
A | Throws checked exception. |
public static <A extends Throwable> void unwrap(Throwable throwable, Class<A> throwableA) throws A
//package com.java2s; //License from project: Apache License import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutionException; public class Main { /**/*from ww w . j a v a2 s .co m*/ * Unwraps ExecutionException thrown from a CompletableFuture. * * @param throwable Throwable to unwrap. * @param throwableA Checked Exception to expose. * @param <A> Class of checked exception. * @throws A Throws checked exception. */ public static <A extends Throwable> void unwrap(Throwable throwable, Class<A> throwableA) throws A { Throwable unwrapThrowable = throwable; if (throwable instanceof ExecutionException || throwable instanceof CompletionException) { unwrapThrowable = throwable.getCause(); } if (throwableA.isInstance(unwrapThrowable)) { throw (A) unwrapThrowable; } if (unwrapThrowable instanceof RuntimeException) { throw (RuntimeException) unwrapThrowable; } if (unwrapThrowable instanceof Error) { throw (Error) unwrapThrowable; } throw new RuntimeException(unwrapThrowable); } /** * Unwraps ExecutionException thrown from a CompletableFuture. * * @param throwable Throwable to unwrap. */ public static void unwrap(Throwable throwable) { unwrap(throwable, RuntimeException.class); } }