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 java.lang.RuntimeException
cleaned(java.lang.Throwable t)
A shortcut forunchecked(unwrapped(t))
.static java.lang.Throwable
close(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 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.io.File against, Throwables.FileOpType opType, Throwables.DiscreteAction<? extends java.io.IOException>... actions)
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 <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(java.io.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:
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 :).
-
-