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 interfaceThrowables.DiscreteAction<E extends java.lang.Exception>static classThrowables.FileOpType
-
Constructor Summary
Constructors Constructor Description Throwables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleananyCauseMatches(java.lang.Throwable t, java.util.function.Predicate<java.lang.Throwable> cause)static java.lang.RuntimeExceptioncleaned(java.lang.Throwable t)A shortcut forunchecked(unwrapped(t)).static java.lang.Throwableclose(java.lang.Throwable accumulate, java.lang.Iterable<? extends java.lang.AutoCloseable> closeables)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 booleanisCausedBy(java.lang.Throwable t, java.util.function.Predicate<java.lang.Throwable> cause)static voidmaybeFail(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 voidperform(java.lang.String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)static java.lang.Throwableperform(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.Throwableperform(java.lang.Throwable accumulate, java.lang.String filePath, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)static java.lang.Throwableperform(java.lang.Throwable accumulate, java.util.Iterator<? extends Throwables.DiscreteAction<?>> actions)static java.lang.Throwableperform(java.lang.Throwable accumulate, java.util.stream.Stream<? extends Throwables.DiscreteAction<?>> actions)static java.lang.Throwableperform(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 voidperform(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.RuntimeExceptionthrowAsUncheckedException(java.lang.Throwable t)throw the exception as a unchecked exception, wrapping if a checked exception, else rethroing as is.static java.lang.RuntimeExceptionunchecked(java.lang.Throwable t)If the provided exception is unchecked, return it directly, otherwise wrap it into aRuntimeExceptionto make it unchecked.static java.lang.Throwableunwrapped(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)
-
close
public static java.lang.Throwable close(java.lang.Throwable accumulate, java.lang.Iterable<? extends java.lang.AutoCloseable> closeables)
-
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:
ExecutionExceptionandCompletionException.
-
unchecked
public static java.lang.RuntimeException unchecked(java.lang.Throwable t)
If the provided exception is unchecked, return it directly, otherwise wrap it into aRuntimeExceptionto 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 :).
-
-