Package org.apache.cassandra.utils
Class Throwables
java.lang.Object
org.apache.cassandra.utils.Throwables
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThrowables.DiscreteAction<E extends Exception>static enum -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleananyCauseMatches(Throwable t, Predicate<Throwable> cause) static voidassertAnyCause(Throwable err, Class<? extends Throwable> cause) static RuntimeExceptionA shortcut forunchecked(unwrapped(t)).static Throwableclose(Throwable accumulate, AutoCloseable... closeables) static Throwableclose(Throwable accumulate, Iterable<? extends AutoCloseable> closeables) Closes all the resources in the provided collections and accumulates the possible exceptions thrown when closing.static voidcloseAndAddSuppressed(Throwable t, AutoCloseable... closeables) static voidcloseAndAddSuppressed(Throwable accumulate, Iterable<AutoCloseable> closeables) Closes all closables in the provided collections and accumulates the possible exceptions thrown when closing.static voidcloseNonNullAndAddSuppressed(Throwable t, AutoCloseable... closeables) Do whatcloseAndAddSuppressed(Throwable, Iterable)does, additionally filtering out all null closables.static Optional<IOException>static <T extends Throwable>
booleanfailIfCanCast(Throwable fail, Class<T> checked) static booleanisCausedBy(Throwable t, Predicate<Throwable> cause) static voidstatic <T extends Throwable>
voidstatic <E extends Exception>
voidmaybeFail(Throwables.DiscreteAction<? extends E>... actions) static <T extends Throwable>
Tmerge(T existingFail, T newFail) static voidperform(String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends IOException>... actions) static Throwableperform(Throwable accumulate, String filePath, Throwables.FileOpType opType, Stream<Throwables.DiscreteAction<? extends IOException>> actions) static Throwableperform(Throwable accumulate, String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends IOException>... actions) static Throwableperform(Throwable accumulate, Iterator<? extends Throwables.DiscreteAction<?>> actions) static Throwableperform(Throwable accumulate, Stream<? extends Throwables.DiscreteAction<?>> actions) static Throwableperform(Throwable accumulate, Throwables.DiscreteAction<?>... actions) static <E extends Exception>
voidperform(Stream<? extends Throwables.DiscreteAction<? extends E>> stream, Throwables.DiscreteAction<? extends E>... extra) static <E extends Exception>
voidperform(Stream<Throwables.DiscreteAction<? extends E>> actions) static voidperform(File against, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends IOException>... actions) static <E extends Exception>
voidperform(Throwables.DiscreteAction<? extends E>... actions) static RuntimeExceptionthrow the exception as a unchecked exception, wrapping if a checked exception, else rethroing as is.static RuntimeExceptionIf the provided exception is unchecked, return it directly, otherwise wrap it into aRuntimeExceptionto make it unchecked.static ThrowableIf the provided throwable is a "wrapping" exception (see below), return the cause of that throwable, otherwise return its argument untouched.
-
Constructor Details
-
Throwables
public Throwables()
-
-
Method Details
-
isCausedBy
-
anyCauseMatches
-
merge
-
maybeFail
-
maybeFail
- Throws:
T extends Throwable
-
failIfCanCast
public static <T extends Throwable> boolean failIfCanCast(Throwable fail, Class<T> checked) throws T - Throws:
T extends Throwable
-
maybeFail
@SafeVarargs public static <E extends Exception> void maybeFail(Throwables.DiscreteAction<? extends E>... actions) -
perform
@SafeVarargs public static <E extends Exception> void perform(Throwables.DiscreteAction<? extends E>... actions) throws E - Throws:
E extends Exception
-
perform
public static <E extends Exception> void perform(Stream<? extends Throwables.DiscreteAction<? extends E>> stream, Throwables.DiscreteAction<? extends E>... extra) throws E - Throws:
E extends Exception
-
perform
public static <E extends Exception> void perform(Stream<Throwables.DiscreteAction<? extends E>> actions) throws E - Throws:
E extends Exception
-
perform
-
perform
public static Throwable perform(Throwable accumulate, Stream<? extends Throwables.DiscreteAction<?>> actions) -
perform
public static Throwable perform(Throwable accumulate, Iterator<? extends Throwables.DiscreteAction<?>> actions) -
perform
@SafeVarargs public static void perform(File against, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends IOException>... actions) -
perform
@SafeVarargs public static void perform(String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends IOException>... actions) -
perform
@SafeVarargs public static Throwable perform(Throwable accumulate, String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends IOException>... actions) -
perform
public static Throwable perform(Throwable accumulate, String filePath, Throwables.FileOpType opType, Stream<Throwables.DiscreteAction<? extends IOException>> actions) -
closeAndAddSuppressed
-
closeNonNullAndAddSuppressed
Do whatcloseAndAddSuppressed(Throwable, Iterable)does, additionally filtering out all null closables. -
closeAndAddSuppressed
public static void closeAndAddSuppressed(@Nonnull Throwable accumulate, Iterable<AutoCloseable> closeables) Closes all closables in the provided collections and accumulates the possible exceptions thrown when closing.- Parameters:
accumulate- non-null exception to accumulate errors thrown when closing the provided resourcescloseables- closeables to be closed
-
close
-
close
Closes all the resources in the provided collections and accumulates the possible exceptions thrown when closing.- Parameters:
accumulate- the initial value for the exception accumulator, can benullcloseables- closeables to be closed- Returns:
null, or the first exception thrown when closing the provided resources
-
extractIOExceptionCause
-
unwrapped
If the provided throwable is a "wrapping" exception (see below), return the cause of that throwable, otherwise return its argument untouched.We call a "wrapping" exception in the context of that method an exception whose only purpose is to wrap another exception, and currently this method recognize only 2 exception as "wrapping" ones:
ExecutionExceptionandCompletionException. -
unchecked
If the provided exception is unchecked, return it directly, otherwise wrap it into aRuntimeExceptionto make it unchecked. -
throwAsUncheckedException
throw the exception as a unchecked exception, wrapping if a checked exception, else rethroing as is. -
cleaned
A shortcut forunchecked(unwrapped(t)). This is called "cleaned" because this basically removes the annoying cruft surrounding an exception :). -
assertAnyCause
-