Class ExceptionUtil
java.lang.Object
org.eclipse.jetty.util.ExceptionUtil
- 
Nested Class Summary
Nested Classes - 
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSuppressedIfNotAssociated(Throwable throwable, Throwable suppressed) Add a suppressed exception if it is not associated.static booleanareAssociated(Throwable t1, Throwable t2) Check if twoThrowables are associated.static booleanareNotAssociated(Throwable t1, Throwable t2) Check if twoThrowables are associated.static <T extends Throwable>
TConvert aThrowableto a specific type by casting or construction on a new instance.static RuntimeExceptionasRuntimeException(Throwable cause) Convert or cast aThrowableto an uncheckedRuntimeException.static voidCall a method that handles aThrowable, catching and associating any exception that it throws.static voidcall(Invocable.Callable callable, Consumer<Throwable> failure) Call aInvocable.Callableand handle any resulting failuresstatic voidcallAndThen(Runnable call, Runnable then) Call aRunnableand then always call another, ignoring any exceptions thrown.static voidcallAndThen(Throwable cause, Consumer<Throwable> call, Runnable then) static voidCall a handler ofThrowableand then always call another, suppressing any exceptions thrown.static ThrowableCombine two, possible null,Throwables in a style to facilitate handling multiple exceptions that are accumulated as suppressed exceptions.static <T> Tget(CompletableFuture<T> completableFuture) Get from aCompletableFutureand convert any uncheck exceptions toRuntimeException.static voidifExceptionThrow(Throwable throwable) static <T extends Throwable>
voidifExceptionThrowAllAs(Class<T> type, Throwable throwable) Throw aThrowableas a specific type, casting or construction as required.static <T extends Throwable>
voidifExceptionThrowAs(Class<T> type, Throwable throwable) Throw aThrowableas a specific type, casting or construction as required.static voidifExceptionThrowUnchecked(Throwable throwable) static voidCall aRunnableand handle failuresstatic StringConvert aThrowableto a string equivalent to whatThrowable.printStackTrace()prints.static <T extends Throwable>
TwithSuppressed(T t, List<Throwable> errors) Decorate a Throwable with the suppressed errors and return it. 
- 
Method Details
- 
as
public static <T extends Throwable> T as(Class<T> type, Throwable throwable) throws IllegalArgumentException Convert a
Throwableto a specific type by casting or construction on a new instance.- Type Parameters:
 T- The type of theThrowableto be returned- Parameters:
 type- The type of the Throwable to be thrown. It must have a constructor that takes aThrowableas a cause.throwable- TheThrowableor null- Returns:
 - A 
Throwableof typeTor null. - Throws:
 IllegalArgumentException- if the passedtypecannot be constructed with a cause.
 - 
ifExceptionThrow
 - 
ifExceptionThrowUnchecked
 - 
asRuntimeException
Convert or cast aThrowableto an uncheckedRuntimeException. - 
ifExceptionThrowAs
public static <T extends Throwable> void ifExceptionThrowAs(Class<T> type, Throwable throwable) throws Error, RuntimeException, T, IllegalArgumentException Throw a
Throwableas a specific type, casting or construction as required.- Type Parameters:
 T- The type of theThrowableto be thrown ifthrowableis not null.- Parameters:
 type- The type of the Throwable to be thrown. It must have a constructor that takes aThrowableas a cause.throwable- AThrowableor null.- Throws:
 Error- If the passedThrowableis anError.RuntimeException- If the passedThrowableis aRuntimeException.T- Thrown inthrowableis not null and neither anErrornorRuntimeException.IllegalArgumentException- if the passedtypecannot be constructed with a cause.
 - 
ifExceptionThrowAllAs
public static <T extends Throwable> void ifExceptionThrowAllAs(Class<T> type, Throwable throwable) throws T Throw a
Throwableas a specific type, casting or construction as required.- Type Parameters:
 T- The type of theThrowableto be thrown ifthrowableis not null.- Parameters:
 type- The type of the Throwable to be thrown. It must have a constructor that takes aThrowableas a cause.throwable- AThrowableor null.- Throws:
 T- Thrown inthrowableis not null and neither anErrornorRuntimeException.
 - 
areAssociated
 - 
areNotAssociated
Check if twoThrowables are associated.- Parameters:
 t1- A Throwable or nullt2- Another Throwable or null- Returns:
 - true iff the exceptions are not associated by being the same instance, sharing a cause or one suppressing the other.
 
 - 
addSuppressedIfNotAssociated
 - 
withSuppressed
 - 
combine
Combine two, possible null,
Throwables in a style to facilitate handling multiple exceptions that are accumulated as suppressed exceptions. This is freqently used in the following pattern:Throwable multiException = null; for (Runnable task : manyThings) { try { task.run(); } catch(Throwable t) { multiException = multiException.combine(multiException, t) } } MultiException.ifExceptionalThrow(multiException);- Parameters:
 t1- A Throwable or nullt2- Another Throwable or null- Returns:
 - t1 with t2 suppressed, or null.
 
 - 
call
 - 
call
Call aInvocable.Callableand handle any resulting failures- Parameters:
 callable- TheInvocable.Callableto callfailure- A handler of failures from the call- See Also:
 
 - 
run
 - 
callAndThen
Call a handler ofThrowableand then always call another, suppressing any exceptions thrown. - 
callAndThen
 - 
callAndThen
 - 
get
Get from a
CompletableFutureand convert any uncheck exceptions toRuntimeException.- Type Parameters:
 T- The type of theCompletableFuture- Parameters:
 completableFuture- The future to get from.- Returns:
 - The value from calling 
CompletableFuture.get() - Throws:
 RuntimeException- if the call toCompletableFuture.get()throws.
 - 
toString
Convert a
Throwableto a string equivalent to whatThrowable.printStackTrace()prints.- Parameters:
 throwable- TheThrowableor null- Returns:
 - a string containing the throwable's full stack trace
 
 
 -