Modifier and Type | Field and Description |
---|---|
static String |
STRINGIFIED_NULL_EXCEPTION
The stringified representation of a null exception reference
|
Modifier and Type | Method and Description |
---|---|
static boolean |
containsThrowable(Throwable throwable,
Class<?> searchType)
Checks whether a throwable chain contains a specific type of exception.
|
static <T extends Throwable> |
firstOrSuppressed(T newException,
T previous)
Adds a new exception as a
suppressed exception
to a prior exception, or returns the new exception, if no prior exception exists. |
static boolean |
isJvmFatalError(Throwable t)
Checks whether the given exception indicates a situation that may leave the
JVM in a corrupted state, meaning a state where continued normal operation can only be
guaranteed via clean process restart.
|
static boolean |
isJvmFatalOrOutOfMemoryError(Throwable t)
Checks whether the given exception indicates a situation that may leave the
JVM in a corrupted state, or an out-of-memory error.
|
static void |
rethrow(Throwable t)
Throws the given
Throwable in scenarios where the signatures do not allow you to
throw an arbitrary Throwable. |
static void |
rethrow(Throwable t,
String parentMessage)
Throws the given
Throwable in scenarios where the signatures do not allow you to
throw an arbitrary Throwable. |
static void |
rethrowException(Throwable t,
String parentMessage)
Throws the given
Throwable in scenarios where the signatures do allow to
throw a Exception. |
static void |
rethrowIfFatalError(Throwable t)
Rethrows the given
Throwable , if it represents an error that is fatal to the JVM. |
static void |
rethrowIfFatalErrorOrOOM(Throwable t)
Rethrows the given
Throwable , if it represents an error that is fatal to the JVM
or an out-of-memory error. |
static void |
rethrowIOException(Throwable t)
Re-throws the given
Throwable in scenarios where the signatures allows only IOExceptions
(and RuntimeException and Error). |
static String |
stringifyException(Throwable e)
Makes a string representation of the exception's stack trace, or "(null)", if the
exception is null.
|
static void |
tryRethrowIOException(Throwable t)
Tries to throw the given
Throwable in scenarios where the signatures allows only IOExceptions
(and RuntimeException and Error). |
public static final String STRINGIFIED_NULL_EXCEPTION
public static String stringifyException(Throwable e)
e
- The exception to stringify.public static boolean isJvmFatalError(Throwable t)
Currently considered fatal exceptions are Virtual Machine errors indicating
that the JVM is corrupted, like InternalError
, UnknownError
,
and ZipError
(a special case of InternalError).
t
- The exception to check.public static boolean isJvmFatalOrOutOfMemoryError(Throwable t)
See isJvmFatalError(Throwable)
for a list of fatal JVM errors.
This method additionally classifies the OutOfMemoryError
as fatal, because it
may occur in any thread (not the one that allocated the majority of the memory) and thus
is often not recoverable by destroying the particular thread that threw the exception.
t
- The exception to check.public static void rethrowIfFatalError(Throwable t)
Throwable
, if it represents an error that is fatal to the JVM.
See isJvmFatalError(Throwable)
for a definition of fatal errors.t
- The Throwable to check and rethrow.public static void rethrowIfFatalErrorOrOOM(Throwable t)
Throwable
, if it represents an error that is fatal to the JVM
or an out-of-memory error. See isJvmFatalError(Throwable)
for a
definition of fatal errors.t
- The Throwable to check and rethrow.public static <T extends Throwable> T firstOrSuppressed(T newException, @Nullable T previous)
suppressed exception
to a prior exception, or returns the new exception, if no prior exception exists.
public void closeAllThings() throws Exception {
Exception ex = null;
try {
component.shutdown();
} catch (Exception e) {
ex = firstOrSuppressed(e, ex);
}
try {
anotherComponent.stop();
} catch (Exception e) {
ex = firstOrSuppressed(e, ex);
}
try {
lastComponent.shutdown();
} catch (Exception e) {
ex = firstOrSuppressed(e, ex);
}
if (ex != null) {
throw ex;
}
}
newException
- The newly occurred exceptionprevious
- The previously occurred exception, possibly null.public static void rethrow(Throwable t)
Throwable
in scenarios where the signatures do not allow you to
throw an arbitrary Throwable. Errors and RuntimeExceptions are thrown directly, other exceptions
are packed into runtime exceptionst
- The throwable to be thrown.public static void rethrow(Throwable t, String parentMessage)
Throwable
in scenarios where the signatures do not allow you to
throw an arbitrary Throwable. Errors and RuntimeExceptions are thrown directly, other exceptions
are packed into a parent RuntimeException.t
- The throwable to be thrown.parentMessage
- The message for the parent RuntimeException, if one is needed.public static void rethrowException(Throwable t, String parentMessage) throws Exception
Throwable
in scenarios where the signatures do allow to
throw a Exception. Errors and Exceptions are thrown directly, other "exotic"
subclasses of Throwable are wrapped in an Exception.t
- The throwable to be thrown.parentMessage
- The message for the parent Exception, if one is needed.Exception
public static void tryRethrowIOException(Throwable t) throws IOException
Throwable
in scenarios where the signatures allows only IOExceptions
(and RuntimeException and Error). Throws this exception directly, if it is an IOException,
a RuntimeException, or an Error. Otherwise does nothing.t
- The Throwable to be thrown.IOException
public static void rethrowIOException(Throwable t) throws IOException
Throwable
in scenarios where the signatures allows only IOExceptions
(and RuntimeException and Error).
Throws this exception directly, if it is an IOException, a RuntimeException, or an Error. Otherwise it
wraps it in an IOException and throws it.t
- The Throwable to be thrown.IOException
public static boolean containsThrowable(Throwable throwable, Class<?> searchType)
throwable
- the throwable chain to check.searchType
- the type of exception to search for in the chain.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.