Package org.apache.cassandra.utils
Class Throwables
- java.lang.Object
-
- org.apache.cassandra.utils.Throwables
-
public final class Throwables extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Throwables.DiscreteAction<E extends java.lang.Exception>
static class
Throwables.FileOpType
-
Constructor Summary
Constructors Constructor Description Throwables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
anyCauseMatches(java.lang.Throwable t, java.util.function.Predicate<java.lang.Throwable> cause)
static void
assertAnyCause(java.lang.Throwable err, java.lang.Class<? extends java.lang.Throwable> cause)
static java.lang.RuntimeException
cleaned(java.lang.Throwable t)
A shortcut forunchecked(unwrapped(t))
.static java.lang.Throwable
close(java.lang.Throwable accumulate, java.lang.AutoCloseable... closeables)
static java.lang.Throwable
close(java.lang.Throwable accumulate, java.lang.Iterable<? extends java.lang.AutoCloseable> closeables)
Closes all the resources in the provided collections and accumulates the possible exceptions thrown when closing.static void
closeAndAddSuppressed(java.lang.Throwable t, java.lang.AutoCloseable... closeables)
static void
closeAndAddSuppressed(java.lang.Throwable accumulate, java.lang.Iterable<java.lang.AutoCloseable> closeables)
Closes all closables in the provided collections and accumulates the possible exceptions thrown when closing.static void
closeNonNullAndAddSuppressed(java.lang.Throwable t, java.lang.AutoCloseable... closeables)
Do whatcloseAndAddSuppressed(Throwable, Iterable)
does, additionally filtering out all null closables.static java.util.Optional<java.io.IOException>
extractIOExceptionCause(java.lang.Throwable t)
static <T extends java.lang.Throwable>
booleanfailIfCanCast(java.lang.Throwable fail, java.lang.Class<T> checked)
static boolean
isCausedBy(java.lang.Throwable t, java.util.function.Predicate<java.lang.Throwable> cause)
static void
maybeFail(java.lang.Throwable fail)
static <T extends java.lang.Throwable>
voidmaybeFail(java.lang.Throwable fail, java.lang.Class<T> checked)
static <E extends java.lang.Exception>
voidmaybeFail(Throwables.DiscreteAction<? extends E>... actions)
static <T extends java.lang.Throwable>
Tmerge(T existingFail, T newFail)
static void
perform(java.lang.String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
static java.lang.Throwable
perform(java.lang.Throwable accumulate, java.lang.String filePath, Throwables.FileOpType opType, java.util.stream.Stream<Throwables.DiscreteAction<? extends java.io.IOException>> actions)
static java.lang.Throwable
perform(java.lang.Throwable accumulate, java.lang.String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
static java.lang.Throwable
perform(java.lang.Throwable accumulate, java.util.Iterator<? extends Throwables.DiscreteAction<?>> actions)
static java.lang.Throwable
perform(java.lang.Throwable accumulate, java.util.stream.Stream<? extends Throwables.DiscreteAction<?>> actions)
static java.lang.Throwable
perform(java.lang.Throwable accumulate, Throwables.DiscreteAction<?>... actions)
static <E extends java.lang.Exception>
voidperform(java.util.stream.Stream<? extends Throwables.DiscreteAction<? extends E>> stream, Throwables.DiscreteAction<? extends E>... extra)
static <E extends java.lang.Exception>
voidperform(java.util.stream.Stream<Throwables.DiscreteAction<? extends E>> actions)
static void
perform(File against, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
static <E extends java.lang.Exception>
voidperform(Throwables.DiscreteAction<? extends E>... actions)
static java.lang.RuntimeException
throwAsUncheckedException(java.lang.Throwable t)
throw the exception as a unchecked exception, wrapping if a checked exception, else rethroing as is.static java.lang.RuntimeException
unchecked(java.lang.Throwable t)
If the provided exception is unchecked, return it directly, otherwise wrap it into aRuntimeException
to make it unchecked.static java.lang.Throwable
unwrapped(java.lang.Throwable t)
If the provided throwable is a "wrapping" exception (see below), return the cause of that throwable, otherwise return its argument untouched.
-
-
-
Method Detail
-
isCausedBy
public static boolean isCausedBy(java.lang.Throwable t, java.util.function.Predicate<java.lang.Throwable> cause)
-
anyCauseMatches
public static boolean anyCauseMatches(java.lang.Throwable t, java.util.function.Predicate<java.lang.Throwable> cause)
-
merge
public static <T extends java.lang.Throwable> T merge(T existingFail, T newFail)
-
maybeFail
public static void maybeFail(java.lang.Throwable fail)
-
maybeFail
public static <T extends java.lang.Throwable> void maybeFail(java.lang.Throwable fail, java.lang.Class<T> checked) throws T extends java.lang.Throwable
- Throws:
T extends java.lang.Throwable
-
failIfCanCast
public static <T extends java.lang.Throwable> boolean failIfCanCast(java.lang.Throwable fail, java.lang.Class<T> checked) throws T extends java.lang.Throwable
- Throws:
T extends java.lang.Throwable
-
maybeFail
@SafeVarargs public static <E extends java.lang.Exception> void maybeFail(Throwables.DiscreteAction<? extends E>... actions)
-
perform
@SafeVarargs public static <E extends java.lang.Exception> void perform(Throwables.DiscreteAction<? extends E>... actions) throws E extends java.lang.Exception
- Throws:
E extends java.lang.Exception
-
perform
public static <E extends java.lang.Exception> void perform(java.util.stream.Stream<? extends Throwables.DiscreteAction<? extends E>> stream, Throwables.DiscreteAction<? extends E>... extra) throws E extends java.lang.Exception
- Throws:
E extends java.lang.Exception
-
perform
public static <E extends java.lang.Exception> void perform(java.util.stream.Stream<Throwables.DiscreteAction<? extends E>> actions) throws E extends java.lang.Exception
- Throws:
E extends java.lang.Exception
-
perform
public static java.lang.Throwable perform(java.lang.Throwable accumulate, Throwables.DiscreteAction<?>... actions)
-
perform
public static java.lang.Throwable perform(java.lang.Throwable accumulate, java.util.stream.Stream<? extends Throwables.DiscreteAction<?>> actions)
-
perform
public static java.lang.Throwable perform(java.lang.Throwable accumulate, java.util.Iterator<? extends Throwables.DiscreteAction<?>> actions)
-
perform
@SafeVarargs public static void perform(File against, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
-
perform
@SafeVarargs public static void perform(java.lang.String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
-
perform
@SafeVarargs public static java.lang.Throwable perform(java.lang.Throwable accumulate, java.lang.String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
-
perform
public static java.lang.Throwable perform(java.lang.Throwable accumulate, java.lang.String filePath, Throwables.FileOpType opType, java.util.stream.Stream<Throwables.DiscreteAction<? extends java.io.IOException>> actions)
-
closeAndAddSuppressed
public static void closeAndAddSuppressed(@Nonnull java.lang.Throwable t, java.lang.AutoCloseable... closeables)
-
closeNonNullAndAddSuppressed
public static void closeNonNullAndAddSuppressed(@Nonnull java.lang.Throwable t, java.lang.AutoCloseable... closeables)
Do whatcloseAndAddSuppressed(Throwable, Iterable)
does, additionally filtering out all null closables.
-
closeAndAddSuppressed
public static void closeAndAddSuppressed(@Nonnull java.lang.Throwable accumulate, java.lang.Iterable<java.lang.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
public static java.lang.Throwable close(java.lang.Throwable accumulate, java.lang.AutoCloseable... closeables)
-
close
public static java.lang.Throwable close(java.lang.Throwable accumulate, java.lang.Iterable<? extends java.lang.AutoCloseable> closeables)
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 benull
closeables
- closeables to be closed- Returns:
null
, {@param accumulate} or the first exception thrown when closing the provided resources
-
extractIOExceptionCause
public static java.util.Optional<java.io.IOException> extractIOExceptionCause(java.lang.Throwable t)
-
unwrapped
public static java.lang.Throwable unwrapped(java.lang.Throwable t)
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:
ExecutionException
andCompletionException
.
-
unchecked
public static java.lang.RuntimeException unchecked(java.lang.Throwable t)
If the provided exception is unchecked, return it directly, otherwise wrap it into aRuntimeException
to make it unchecked.
-
throwAsUncheckedException
public static java.lang.RuntimeException throwAsUncheckedException(java.lang.Throwable t)
throw the exception as a unchecked exception, wrapping if a checked exception, else rethroing as is.
-
cleaned
public static java.lang.RuntimeException cleaned(java.lang.Throwable t)
A shortcut forunchecked(unwrapped(t))
. This is called "cleaned" because this basically removes the annoying cruft surrounding an exception :).
-
assertAnyCause
public static void assertAnyCause(java.lang.Throwable err, java.lang.Class<? extends java.lang.Throwable> cause)
-
-