public class Exceptions extends Object
| Modifier and Type | Field and Description |
|---|---|
static Thread.UncaughtExceptionHandler |
SILENT_UNCAUGHT_EXCEPTION_HANDLER |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
chain(T initial,
T current) |
static <E extends Throwable> |
combine(E first,
E second)
Deprecated.
Use
Throwable.addSuppressed(Throwable) and Throwable.initCause(Throwable) where
appropriate instead. |
static boolean |
contains(Throwable cause,
Class... anyOfTheseClasses) |
static boolean |
contains(Throwable cause,
Predicate<Throwable> toLookFor) |
static boolean |
contains(Throwable cause,
String containsMessage,
Class... anyOfTheseClasses) |
static <T extends Throwable> |
launderedException(Class<T> type,
String messageForUnexpected,
Throwable exception)
Deprecated.
use
throw e or throw new RuntimeException(e) directly. Prefer multi-caches if applicable.
For more elaborate scenarios, have a look at throwIfUnchecked(Throwable) and
throwIfInstanceOf(Throwable, Class)
For a more furrow explanation take a look at the very similar case:
Why we deprecated |
static <T extends Throwable> |
launderedException(Class<T> type,
Throwable exception)
Deprecated.
|
static RuntimeException |
launderedException(String messageForUnexpected,
Throwable exception)
Deprecated.
|
static RuntimeException |
launderedException(Throwable exception)
Deprecated.
|
static Throwable |
peel(Throwable exception,
Predicate<Throwable> toPeel)
Peels off layers of causes.
|
static Throwable |
rootCause(Throwable caughtException)
Returns the root cause of an exception.
|
static void |
setMessage(Throwable cause,
String message) |
static String |
stringify(Thread thread,
StackTraceElement[] elements) |
static String |
stringify(Throwable throwable) |
static <T extends Throwable> |
throwIfInstanceOf(Throwable exception,
Class<T> clazz)
Will rethrow the provided
exception if it is an instance of clazz. |
static void |
throwIfUnchecked(Throwable exception)
|
static <T extends Throwable> |
withCause(T exception,
Throwable cause)
Deprecated.
Use
Throwable.initCause(Throwable) instead. |
static <T extends Throwable> |
withMessage(T cause,
String message) |
static <T extends Throwable> |
withSuppressed(T exception,
Throwable... suppressed)
Deprecated.
Use
Throwable.addSuppressed(Throwable) instead. |
public static final Thread.UncaughtExceptionHandler SILENT_UNCAUGHT_EXCEPTION_HANDLER
public static void throwIfUnchecked(Throwable exception)
exception if it is an instance of RuntimeException or Error. Typical usage is:
catch (Throwable e) {
......common code......
throwIfUnchecked(e);
throw new RuntimeException(e);
}
This will only wrap checked exception in a RuntimeException. Do note that if the segment common code
is missing, it's preferable to use this instead:
catch (RuntimeException | Error e) {
throw e;
}
catch (Throwable e) {
throw new RuntimeException(e);
}
exception - to rethrow.public static <T extends Throwable> void throwIfInstanceOf(Throwable exception, Class<T> clazz) throws T extends Throwable
exception if it is an instance of clazz. Typical usage is:
catch (Throwable e) {
......common code......
throwIfInstanceOf(e, BarException.class);
throw new RuntimeException(e);
}
This will filter out all BarExceptions and wrap the rest in RuntimeException. Do note that if the
segment common code is missing, it's preferable to use this instead:
catch (BarException e) {
throw e;
} catch (Throwable e) {
threw new RuntimeException(e);
}
@Deprecated public static <T extends Throwable> T withCause(T exception, Throwable cause)
Throwable.initCause(Throwable) instead.@Deprecated public static <T extends Throwable> T withSuppressed(T exception, Throwable... suppressed)
Throwable.addSuppressed(Throwable) instead.@Deprecated public static RuntimeException launderedException(Throwable exception)
launderedException(Class, String, Throwable).@Deprecated public static RuntimeException launderedException(String messageForUnexpected, Throwable exception)
launderedException(Class, String, Throwable).@Deprecated public static <T extends Throwable> T launderedException(Class<T> type, Throwable exception)
launderedException(Class, String, Throwable).@Deprecated public static <T extends Throwable> T launderedException(Class<T> type, String messageForUnexpected, Throwable exception)
throw e or throw new RuntimeException(e) directly. Prefer multi-caches if applicable.
For more elaborate scenarios, have a look at throwIfUnchecked(Throwable) and
throwIfInstanceOf(Throwable, Class)
For a more furrow explanation take a look at the very similar case:
Why we deprecated Throwables.propagate
public static Throwable peel(Throwable exception, Predicate<Throwable> toPeel)
exception - the outer exception to peel to get to an delegate cause.toPeel - Predicate for deciding what to peel. true means
to peel (i.e. remove), whereas the first false means stop and return.public static Throwable rootCause(Throwable caughtException)
caughtException - exception to find the root cause of.IllegalArgumentException - if the provided exception is null.public static String stringify(Thread thread, StackTraceElement[] elements)
public static boolean contains(Throwable cause, String containsMessage, Class... anyOfTheseClasses)
@Deprecated public static <E extends Throwable> E combine(E first, E second)
Throwable.addSuppressed(Throwable) and Throwable.initCause(Throwable) where
appropriate instead.public static <T extends Throwable> T chain(T initial, T current)
Copyright © 2002–2019 The Neo4j Graph Database Project. All rights reserved.